Repository navigation
fix(web): 拖动选择文字经过输入框时不再中断 / keep drag selection going past the composer - #1366
Conversation
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.
|
No actionable comments were generated in the recent review. Summary
Merge Risk:
|
摘要
在对话里按住鼠标从回答文字往下拖选,指针一碰到底部输入框,选区就消失,输入框获得焦点,之后继续拖也选不上文字。原问题来自桌面端(WebKit)的录屏。
原因:
.composerSeat是对话滚动区[data-conversation-scroll]里的 sticky 元素,盖在对话内容上。指针移到输入框上时仍在滚动区内部。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 的两条规则。修复后在两个引擎里还检查了:
dragstart时标记已清除,链接正常放入(WebKit 放入链接文字,Chrome 放入网址)。其他:
prettier --check通过(pre-commit 钩子)。新模块用tsc --strict单独检查通过;apps/web-ui源码不在仓库的 typecheck 范围内。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:
.composerSeatis 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.focus()or changes the selection; this was confirmed in Playwright WebKit by tracingfocus(), theSelectionmethods andselectionchange. Chrome does not take focus, but extends the selection straight to the end of the conversation.Change:
transcript-selection-drag.ts: a capturepointerdownlistener on the scrollport. A primary mouse press outside the composer seat setsdata-selection-dragon the scrollport;pointerup,pointercancel,dragstart,contextmenuor windowblurremoves it.ConversationContentinstalls it on mount and cleans it up on unmount.ConversationRoot.module.css:pointer-events: noneon 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.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.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.dragstartand can still be dropped into the composer. OnlypointerType === "mouse"is handled; touch and pen are unaffected.Related issues
N/A
Test plan
Environment:
npm start web -- --port 4401from 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.Also checked after the fix in both engines:
dragstartand the link is dropped (WebKit inserts the link text, Chrome the URL).Other:
prettier --checkpasses on the changed files (pre-commit hook). The new module passes a standalonetsc --strictcheck;apps/web-uisources are not part of the repository typecheck.UI Demo
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.