Skip to content

fix(web): 拖动选择文字经过输入框时不再中断 / keep drag selection going past the composer - #1366

Merged
iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
sduhantao-maker:fix/web-drag-select-composer
Nov 28, 2026
Merged

iruriQ merged 1 commit into
BytePioneer-AI:mainfrom
sduhantao-maker:fix/web-drag-select-composer

Conversation

@sduhantao-maker

Copy link
Copy Markdown
Contributor

摘要

在对话里按住鼠标从回答文字往下拖选,指针一碰到底部输入框,选区就消失,输入框获得焦点,之后继续拖也选不上文字。原问题来自桌面端(WebKit)的录屏。

原因:

  • 输入框所在的 .composerSeat 是对话滚动区 [data-conversation-scroll] 里的 sticky 元素,盖在对话内容上。指针移到输入框上时仍在滚动区内部。
  • 拖动选择进入输入框的可编辑区(Lexical 的 contenteditable)时,WebKit 自己先清空页面选区,再把光标放进可编辑区并聚焦。页面脚本没有调用 focus(),也没有改动选区:在 Playwright WebKit 里跟踪 focus()、Selection 的方法和 selectionchange 确认过。Chrome 不抢焦点,但会把选区直接扩到对话末尾。
  • 浏览器只在指针到达滚动区边缘(这里就是窗口底边)时才为选区自动滚动。输入框占着滚动区底部,所以拖到输入框上对话不会滚。

改动:

  • 新增 transcript-selection-drag.ts:在滚动区上以 capture 监听 pointerdown。鼠标左键在输入框区域以外按下时,给滚动区加 data-selection-drag;pointerup、pointercancel、dragstart、contextmenu 或窗口 blur 时去掉。ConversationContent 挂载时安装,卸载时清理。
  • 标记存在时,ConversationRoot.module.css:
    • 让输入框区域里的可编辑元素(input、textarea、contenteditable)pointer-events: none。WebKit 不再把选区收进输入框。输入框区域的其余部分照常命中,选区和以前一样扩到对话末尾。
    • 给滚动区加 scroll-padding-bottom: var(--dsh-composer-height)。这个变量是输入框区域的高度,由已有的 ResizeObserver 维护。两个引擎的选区自动滚动都把 scroll-padding 计入可视范围,所以指针一进入输入框区域,对话就开始滚动,效果和输入框在滚动区外面时一样。
  • 没有让整个输入框区域 pointer-events: none。对话滚到底时,输入框下面没有对话内容,WebKit 会把那里的点解析到很靠上的位置,选区会反向。
  • 从对话拖出链接等原生拖放会在 dragstart 时去掉标记,仍能放进输入框。只处理 pointerType === "mouse",触屏和笔不受影响。

关联 Issue

无 / N/A

测试

环境:本分支的 npm start web -- --port 4401(独立数据目录),用 Playwright 1.62 的 WebKit(与桌面端同一引擎)和本机 Chrome(headless),窗口 1400×900 和 1000×680。打开一段较长的已有对话,往上滚动一段,从回答文字按下后往下拖到输入框,停留约 1 秒,再移回对话文字上。修复前的数据来自同一构建,用注入的 CSS 抵消本 PR 的两条规则。

场景 WebKit 修复前 WebKit 修复后 Chrome 修复前 Chrome 修复后
指针进入输入框的可编辑区 选区清空,输入框获得焦点 选区保留并扩到对话末尾,焦点不变 选区扩到对话末尾,焦点不变 同修复前
指针停在输入框上约 1 秒 对话不滚动 对话滚到底,选区停在对话末尾 对话不滚动,指针到窗口底边才滚 对话滚到底,选区停在对话末尾
再把指针移回对话文字上 仍选不上文字 选区跟随指针 选区跟随指针 选区跟随指针
拖动前输入框已有焦点 同第一行 同第一行 焦点不变 焦点不变

修复后在两个引擎里还检查了:

  • 单击输入框仍会聚焦;在对话区按下再松开后标记清除,随后单击输入框正常。
  • 从对话拖到发送按钮上松开:不发送,输入框不获得焦点。
  • 右键按下、Control+单击(触发 contextmenu)都不留下标记。
  • 在输入框内拖选文字正常。
  • 从对话拖一个链接放进输入框:dragstart 时标记已清除,链接正常放入(WebKit 放入链接文字,Chrome 放入网址)。

其他:

  • 改动文件的 prettier --check 通过(pre-commit 钩子)。新模块用 tsc --strict 单独检查通过;apps/web-ui 源码不在仓库的 typecheck 范围内。
  • 按 AGENTS.md,Web 页面不写组件测试。
  • 未覆盖:桌面端 WKWebView 本体(用 Playwright WebKit 代替)、Safari、Firefox、触屏设备。
  • 已知且未处理:WebKit 里指针拖出窗口下边缘时选区会反向扩到上方。修复前沿输入框右侧绕出窗口也是这样,不是本 PR 引入的。

UI Demo

左:修复前拖到输入框时选区消失、输入框获得焦点;右:修复后对话自动滚动,选区继续扩展

左为修复前,右为修复后,同一段对话、同一条拖动路径。由 Playwright WebKit 录制,窗口 1000×680。对话正文、标题、链接和模型名已在页面里替换为占位文字,用量信息已隐藏,侧栏已收起。


Summary

In a conversation, a mouse selection dragged down from an answer stops working once the pointer touches the composer at the bottom: the selection disappears, the composer takes focus, and further dragging selects nothing. The original report is a screen recording from the desktop shell (WebKit).

Cause:

  • The composer's .composerSeat is a sticky element inside the conversation scrollport [data-conversation-scroll] and covers the transcript. With the pointer over the composer, it is still inside the scrollport.
  • When a drag selection reaches the composer's editable (Lexical's contenteditable), WebKit itself clears the page selection, then puts a caret in the editable and focuses it. No page script calls focus() or changes the selection; this was confirmed in Playwright WebKit by tracing focus(), the Selection methods and selectionchange. Chrome does not take focus, but extends the selection straight to the end of the conversation.
  • Browsers autoscroll a selection only when the pointer reaches the scrollport's edge, which here is the window's bottom edge. The composer occupies the bottom of the scrollport, so dragging onto it does not scroll the conversation.

Change:

  • New transcript-selection-drag.ts: a capture pointerdown listener on the scrollport. A primary mouse press outside the composer seat sets data-selection-drag on the scrollport; pointerup, pointercancel, dragstart, contextmenu or window blur removes it. ConversationContent installs it on mount and cleans it up on unmount.
  • While the mark is set, ConversationRoot.module.css:
    • Sets pointer-events: none on the seat's editable fields (input, textarea, contenteditable), so WebKit no longer collapses the selection into the composer. The rest of the seat is still hit-tested, and the selection extends to the end of the conversation as before.
    • Sets scroll-padding-bottom: var(--dsh-composer-height) on the scrollport. The variable is the seat's height, kept current by the existing ResizeObserver. Selection autoscroll in both engines counts scroll-padding when it computes the visible area, so the conversation starts scrolling as soon as the pointer enters the composer, as it would if the composer sat outside the scrollport.
  • The whole seat is not made pointer-events: none. When the conversation is scrolled to the end, there is no transcript under the composer, and WebKit resolves a point there to a position far above, which reverses the selection.
  • A native drag-and-drop out of the transcript, such as a link, clears the mark on dragstart and can still be dropped into the composer. Only pointerType === "mouse" is handled; touch and pen are unaffected.

Related issues

N/A

Test plan

Environment: npm start web -- --port 4401 from this branch with a separate data directory, Playwright 1.62 WebKit (the desktop shell's engine) and the local Chrome (headless), at 1400×900 and 1000×680. A long existing conversation was scrolled up a little; the drag started on answer text, moved down onto the composer, rested there for about one second, then moved back onto transcript text. The "before" data comes from the same build with injected CSS that cancels this PR's two rules.

Case WebKit before WebKit after Chrome before Chrome after
Pointer enters the composer's editable Selection cleared, composer focused Selection kept and extended to the end of the conversation, focus unchanged Selection extended to the end of the conversation, focus unchanged Same as before
Pointer rests on the composer for about one second No scrolling Conversation scrolls to the end; selection stops at the end No scrolling until the pointer reaches the window's bottom edge Conversation scrolls to the end; selection stops at the end
Pointer moves back onto transcript text Still nothing can be selected Selection follows the pointer Selection follows the pointer Selection follows the pointer
Composer focused before the drag Same as the first row Same as the first row Focus unchanged Focus unchanged

Also checked after the fix in both engines:

  • Clicking the composer still focuses it; after a press and release in the transcript the mark is cleared, and the next click on the composer works.
  • Dragging from the transcript and releasing over the Send button does not send and does not focus the composer.
  • A right-button press and a Control-click (which fires contextmenu) leave no mark behind.
  • Selecting text inside the composer by dragging works.
  • Dragging a link from the transcript into the composer: the mark is already cleared at dragstart and the link is dropped (WebKit inserts the link text, Chrome the URL).

Other:

  • prettier --check passes on the changed files (pre-commit hook). The new module passes a standalone tsc --strict check; apps/web-ui sources are not part of the repository typecheck.
  • Per AGENTS.md, no component tests for Web pages.
  • Not covered: the desktop shell's WKWebView itself (Playwright WebKit stands in for it), Safari, Firefox and touch devices.
  • Known and not addressed: in WebKit, dragging the pointer below the window's bottom edge reverses the selection upward. Before this change the same happens when the pointer leaves the window beside the composer, so this PR does not introduce it.

UI Demo

Left: before, the selection disappears and the composer takes focus; right: after, the conversation scrolls and the selection keeps extending

Left is before, right is after: the same conversation and the same drag path, recorded with Playwright WebKit at 1000×680. Message text, titles, links and the model name were replaced with placeholder text in the page, usage information is hidden, and the sidebar is collapsed.

The composer seat is sticky inside the conversation scrollport, so a mouse
selection dragged from the transcript onto it never leaves the scrollport.
WebKit (the desktop shell) then collapses the selection into the composer's
editable and focuses it, and selection autoscroll waits for the window's
bottom edge. While a primary mouse press that began in the transcript is
held, take the seat's editable fields out of hit testing and pad the
scrollport's end by the seat height, so the selection survives and the
browser's own autoscroll starts at the composer.
@coderabbitai

coderabbitai Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 体验优化
    • 在会话内容中拖动选择文本时,经过输入区域仍可继续由滚动区域处理拖选,减少选择中断。
    • 拖选期间为滚动区域预留输入框高度对应的底部空间,改善靠近会话底部时的文本选择体验。

新增会话文本选择拖拽跟踪。在滚动区符合条件的主键鼠标按下后设置标记,并在结束事件、失焦或组件清理时移除标记。拖拽期间,样式调整滚动区域底部留白,并禁用 composer seat 内相关控件的指针事件。

Changes: 会话文本选择拖拽

Layer / File(s) Summary
拖拽事件跟踪
apps/web-ui/packages/client/ui-conversation/src/client/skeleton/transcript-selection-drag.ts
新增 trackTranscriptSelectionDrag。目标不在 composer seat 内时,主键鼠标按下会设置滚动区标记。窗口收到结束事件或失焦时,函数会清除标记和相关监听器。
组件接入与拖拽样式
apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx, apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.module.css
ConversationContent 在 body 变化时启动跟踪,并使用返回值清理。拖拽标记生效时,样式为滚动区增加底部留白,并禁用 composer seat 内 input、textarea 和可编辑元素的指针事件。

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant TranscriptScrollRegion
  participant ComposerSeat
  participant Window
  TranscriptScrollRegion->>ComposerSeat: 检查按下目标是否位于 seat 内
  TranscriptScrollRegion->>TranscriptScrollRegion: 符合条件时设置拖拽标记
  Window->>TranscriptScrollRegion: 结束事件或失焦时清除标记
Loading

Suggested reviewers: bytepioneer-ai, zxd-666

Merge Risk: Minimal · up to dd76c

The change keeps text selection going when dragging past the composer and is limited to the conversation scroll area. No actionable merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed 标题描述了本 PR 的主要改动:拖动选择文字经过底部输入框时,选区不再中断。标题与变更集(新增 transcript-selection-drag.ts,并在 CSS 中禁用输入框可编辑元素的指针事件、添加 scroll-padding-bottom)直接相关。标题使用了中英双语,长度 72 个字符,略长,但仍清楚、具体。
Description check Passed 描述说明了问题来源(WebKit 中拖选经过输入框时选区消失、输入框获得焦点),并说明了原因、改动方案、测试环境和测试结果。描述与变更集直接相关,内容完整。
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between b2cfe71 and dd76c23.

Files selected for processing: 3

  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx
  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.module.css
  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/transcript-selection-drag.ts

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Recent review details

Context from checks skipped due to timeout: 4

  • GitHub Check: CodeRabbit
  • GitHub Check: Vitest
  • GitHub Check: Static checks
  • GitHub Check: Web Host tests
Additional context used

Code guidelines: 1

CLAUDE.md — auto-discovered
Path-based instructions: 1

Source excerpt: Do not write browser, e2e, or component tests for Web pages (`apps/web-ui`); the user checks page changes directly.

CodeRabbit inference engine (CLAUDE.md)

Files:

  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationContent.tsx
  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/ConversationRoot.module.css
  • apps/web-ui/packages/client/ui-conversation/src/client/skeleton/transcript-selection-drag.ts
Learnings: 1

Common learnings

Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: AGENTS.md:0-0
Timestamp: 2026-11-27T09:29:53.369Z
Learning: Source excerpt:
# Repository Guidelines

## Testing & Completion

- Do not write browser, e2e, or component tests for Web pages (`apps/web-ui`); the user checks page changes directly. Codex Desktop compatibility after an update is checked with `npm run audit:codex-desktop` and `npm run probe:renderer-binding` (`codexhost-update-impact-audit`).
Learnt from: CR
Repo: BytePioneer-AI/codex-host PR: 0
File: CLAUDE.md:0-0
Timestamp: 2026-11-28T11:13:45.993Z
Learning: Applies to apps/web-ui/** : Source excerpt:
# Repository Guidelines

## Testing & Completion

- Do not write browser, e2e, or component tests for Web pages (`apps/web-ui`); the user checks page changes directly. Codex Desktop compatibility after an update is checked with `npm run audit:codex-desktop` and `npm run probe:renderer-binding` (`codexhost-update-impact-audit`).

@iruriQ
iruriQ merged commit d93ac3d into BytePioneer-AI:main Nov 28, 2026
7 checks passed
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