Skip to content

fix: robust annotation editor positioning (degenerate rect guard, z-index, Esc close) - #2

Open
chenyuhao0628 wants to merge 2 commits into
wangwei-wade:mainfrom
chenyuhao0628:fix/editor-positioning-robustness
Open

fix: robust annotation editor positioning (degenerate rect guard, z-index, Esc close)#2
chenyuhao0628 wants to merge 2 commits into
wangwei-wade:mainfrom
chenyuhao0628:fix/editor-positioning-robustness

Conversation

@chenyuhao0628

Copy link
Copy Markdown

问题描述

选区批注/回合引用按钮点击后,悬浮编辑框偶尔会卡在视口左上角并盖住左侧会话列表,且 按钮点不掉:

  • 触发时机:会话流式输出 / 列表重渲染期间点击「批注」或「引用提问 / 引用回答」按钮,getBoundingClientRect() 可能返回零尺寸矩形(按钮节点在点击与测量之间脱离 DOM),定位逻辑 Math.max(12, ...) 把编辑框钳制到左上角 (12, 8)。
  • 编辑框未设置 z-index(选区气泡/悬停提示都有 2147483000),关闭按钮可能被其他层遮挡。
  • 全局 Esc 只关闭气泡/提示/toast,不关闭编辑框

修复内容

  1. rectOf 健壮化:节点已脱离 DOM(isConnected === false)或矩形为零尺寸时返回 null,不再把脏矩形传给编辑框。
  2. 兜底定位 fallbackRect:锚点矩形失效时,编辑框定位到视口下部居中(输入框上方),而不是左上角。
  3. 完整视口钳制:编辑框优先锚点下方 → 上方 → 视口下部三级回退,estH 修正为实际高度 236。
  4. z-index: 2147483000.dshq-editor.dshq-toolbar 显式提升, 永远可点。
  5. 全局 Esc 关闭编辑框:与气泡/toast 一致。
  6. 选区气泡下沿分支补 vh 钳制,避免贴底选区把气泡推出屏幕。

验证

  • 正常路径(可见按钮 / 正常选区)定位行为不变:headless 实测 1440×900 与 1280×860 下均正确。
  • 异常路径(程序化点击屏幕外按钮 → 零尺寸矩形)修复前编辑框落到 (407, -10032) 屏幕外;修复后使用兜底位置。
  • 截图复现:左上角卡住编辑框盖住侧边栏的现象不再出现。

- rectOf: reject detached/zero-size anchor rects (getBoundingClientRect
  returns zeros when the clicked node was detached mid-render, which made
  the editor clamp to the viewport top-left corner and cover the sidebar)
- AnnotationEditor: fallback anchor position (lower-center of viewport)
  for degenerate rects; clamp both above/below branches into the viewport
- give .dshq-editor and .dshq-toolbar an explicit high z-index so the
  close button can never be covered by other layers
- global Escape now also closes the annotation editor (previously only
  via the input's own keydown)
- selection toolbar: clamp below-branch so the bubble stays on-screen
- extractTurnTexts / selectTurnQuote: try/catch so a malformed snapshot
  can never crash the turnTail entry and silently remove the buttons
- registerSource: guard the duplicate-registration throw on hot reload
  so apply() cannot die halfway (global listeners + slot registration)
- stage(): visible warning when no session is available instead of a
  silent no-op; sync currentSessionId from the turn-tail path so anchor
  jumps keep working after switching sessions
@chenyuhao0628
chenyuhao0628 force-pushed the fix/editor-positioning-robustness branch from 8c24ff7 to 1f162fa Compare August 17, 2026 08:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants