Repository navigation
fix(reader): 标注编辑器的文本框自己滚动时不再关掉面板 - #4
Merged
2019wakeup merged 1 commit intoNov 23, 2026
Merged
Conversation
The page-level dismissal listener sits on window in the capture phase, so it also received scroll events from the annotation editor's own textarea and from any scrolling card: the first wheel or caret scroll inside the note field cleared the editing state and the panel vanished mid-typing. Scroll dismissal now goes through a policy in menu.js, next to the existing pointer policy: a scroll that starts inside a panel or an editable field is not the reading surface moving under the anchor, while a window-level scroll (or one landing in the prose) still closes the panels as before. Give the annotation note field a usable size (96px) scoped to .rd-annotation-editor so the concept edit form keeps its compact fields, pin the save/delete/close row with the existing sticky-action class, and add real-browser scenarios that type into the field, scroll it, and then scroll the page.
liujieranjerry-lgtm
force-pushed
the
fix/annotation-editor-scroll
branch
from
November 23, 2026 08:37
bc5117a to
5bef4b4
Compare
2019wakeup
approved these changes
Nov 23, 2026
2019wakeup
left a comment
Owner
There was a problem hiding this comment.
验证通过(PR 基线即当前 main):node --test 250/250、node eval/run.mjs 13/13、node eval/layout-host.mjs 6/6、node eval/visual.mjs 122/122。新增 DOM 用例真实挂载 client.js,覆盖了 textarea 自滚动、.rd-quote 自滚动、正文滚动关闭三条路径;视觉用例也验证了 102px 的文本框滚动和面板保持。
代码上把滚动关闭策略收敛到 menu.js,和 shouldDismissOnPointerDown 并列,选择器包含可编辑元素与浮动面板;正文/window 滚动仍关闭,保留了既有行为。.rd-annotation-editor 的样式作用域也避开了概念编辑表单。
两个备注(不阻塞合并):1) 滚动右侧抽屉时仍会关闭标注编辑器,这是既有行为,本次未扩大范围;2) 正文滚动关闭时草稿不落盘,作者已在 PR 中明确列为后续项。合并。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
症状
在正文里点选一处高亮标注打开「编辑标注」面板后,只要备注写得超过三行(文本框约 96px 高、内部开始出现滚动),继续往下滚或按住光标往下拖,面板会直接消失,正在写的备注一起丢掉。右侧抽屉、卡片自己的滚动也受同一问题影响。
根因
src/client/app.js的文档级关闭逻辑把滚动监听挂在window上,并且用了捕获阶段:scroll事件不冒泡,但捕获阶段仍然会从window一路走到目标节点,所以任何后代元素自己滚动(备注文本框、.rd-quote、.rd-card内部滚动)都会触发它,把editing清空、面板卸载。点击取消逻辑早就做过区域判断(menu.js的shouldDismissOnPointerDown用closest('.rd-mini, .rd-card')放行面板内部),滚动这条路径没有对应判断——这是漏掉了同一类判断,不是新引入的问题。顺带三个放大器:文本框只有
min-height:64px(约三行,正好对应用户说的「超过三行」);.rd-editor textarea没有overscroll-behavior,滚到底会链式带动页面滚动;操作按钮原来是普通行,卡片滚动时会被滚出视野。改动
src/client/menu.js:新增shouldDismissOnScroll(target),把滚动关闭策略和已有的点击关闭策略放在一起。目标落在可编辑元素(textarea/input/select/[contenteditable])或面板容器(.rd-mini, .rd-card, .rd-trans-card)内部 ⇒ 不关闭;window/document/null目标或落在正文 ⇒ 仍然关闭。src/client/app.js:onScroll改为onScroll = (event) => { if (!shouldDismissOnScroll(event.target)) return; … };备注文本框的根节点加上.rd-annotation-editor类;操作行改用仓库里已有的rd-sticky-actions。src/client/styles.js:备注文本框改成min-height:96px; max-height:min(34vh,260px); overflow:auto; overscroll-behavior:contain,并且只挂在.rd-annotation-editor下——概念编辑表单复用.rd-editor,不隔离会把它的四个 textarea 一起撑高(第一版就是这么写的,视觉基线03c-concept-edit直接 diff 1.44%,见下)。二阶 / 三阶影响
test/editor-flow.test.mjs「scrolling closes the editor」)锁定,本次保留。overscroll-behavior:contain后,滚到文本框底部不会再把滚动传给正文,也就不会出现「滚完面板消失」的连带效应;关闭面板只剩两条明确路径:点正文、或滚正文。.rd-editor textarea被概念编辑表单共用,所以高度只挂在新增的.rd-annotation-editor上,概念编辑表单的布局不变(03c 基线恢复通过)。menu.js一处,和点击策略并列,后续新增浮层(翻译卡、卡片菜单)只要进同一组选择器即可,不需要再改事件处理函数。验证
node --test test/*.test.mjs→ 250/250(新增test/annotation-editor-scroll.test.mjs,jsdom 挂真实client.js:打开标注编辑器 → 输入 5 行备注 → 在 textarea /.rd-quote上派发scroll→ 断言面板还在、备注还在 → 在.rd-main上派发scroll→ 断言关闭;修复前该用例为红)node eval/run.mjs→ 13/13node eval/layout-host.mjs→ 6/6node eval/visual.mjs(真实 Chrome + 真实client.js)→ 121/122,唯一失败项markdown relative images load through the file route在未改动的main上同样失败(缺图片资源的既有环境问题)。新增三条浏览器断言:备注框自己能滚(scrollTop 102)、滚备注框时面板保持、滚正文时面板关闭。03d-annotation-editor(备注框变高、按钮吸底,预期变化)、03e-note-box(前一步耗时变长,截图里的 transient toast「已收下」已经消失;同时给两张图加了「等 toast 消失」的显式等待,避免以后按运行速度抖动)。node scripts/build-client.mjs重建后git status干净,产物与源码一致。服务端
index.js未改动,纯前端改动。