perf(conversation): ignore idle width-handle pointer movement
This commit is contained in:
1 parent
5ff9ab8757
commit
97daa6a799
6 files changed
+50
-13
No files matched your search
@@ -2,5 +2,5 @@
|
||||
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
||||
# after editing either side, bring the other along and re-record with:
|
||||
# pnpm run verify-translation-pairing --write packages/client/ui-conversation/README.md
|
||||
README.md: 33c857da49e5e32bd2582d6cd3bcb9650d3fd651
|
||||
README.zh.md: 8dc52d4a5f8573f190a89997a6ae23431a7c7037
|
||||
README.md: e67533ea47184d4a25563aad657919eed4a372b3
|
||||
README.zh.md: d2d87ea49b0e9fd214b2bc39b88c852b5d9b27cb
|
||||
@@ -66,6 +66,8 @@ The shell reads the persisted View preference before rendering when a Session fi
|
||||
|
||||
Active transcripts in the main occurrence expose content-width drag handles in their uncovered side gutters; embedded occurrences omit them. A View that paints into a gutter raises only its concrete painted element above the handle; transparent full-width wrappers stay below so they do not claim empty gutter. This requires the path between that element and the Conversation body to remain outside an intermediate stacking context; the shipped Chromium behavior is pinned by the browser scenario. Chat applies the rule to table elements, while its column-bounded tool cards need no raise. Wheel motion over a handle still scrolls the transcript, while Ctrl+wheel remains a browser zoom gesture. The sticky composer intentionally owns its full footer band, which is not a resize target; an already-captured drag lifts its indicator until release ([handle styles](src/client/skeleton/ConversationRoot.module.css)).
|
||||
|
||||
Width-handle pointer moves first check a synchronous dragging ref, then pointer capture, before reading layout, writing styles, or scheduling animation frames. Pointer handlers update the drag indicator directly without a React state update. The indicator follows the pointer only during a captured drag; ordinary hover leaves its position unchanged.
|
||||
|
||||
The resident composer survives no-Session and Session transitions. Whitespace hides its placeholder; a whitespace-only draft without attachments cannot be sent. The no-Session state keeps the same composer surface mounted but inert while the Workspace picker connects a blank Session. The surface is a shell-owned Lexical editor: reference chips are atomic decorator nodes carrying the owner's serialization identity (submission expands them through the owner codec), claimed slash commands stay styled leading text, folder text references carry the folder glyph as an icon prefix, and the draft's clipboard projection is mirrored into the per-Session Conversation store. QueueDock reads `next-turn` directly from the Session `inbox` projection, including cold recovered messages. Queue operations address exact queue occurrences through the scoped `ctx.conversation` service; queue previews render sent text through the shared inline reference projection from `ui-primitives` (wire session forms fold to their label) and show local or durable images and files in original attachment order. Images use thumbnails; files use compact name-and-size cards. An edit exposes the literal sent text, and durable thumbnails resolve through the session image URL cache. Busy Enter behavior is stored in the Host-backed `ui-conversation` settings namespace. The composer keymap arbitrates the trigger menu's keys through the slash pipeline — Tab settles the highlighted completion (or drills a drillable one), Escape and Shift+Tab leave the menu without settling — and leaves every other key to the editor. An overlay that takes the keyboard hands it back through `SessionInput.focus()`, which rides Lexical's own focus so the caret returns where the draft left it rather than at the start.
|
||||
|
||||
Default sends commit optimistically: Enter clears the draft, occurrence table, and undo history in the same transaction, keeps the composer in `plain`, and runs the send as a detached attempt, so typing and further sends continue during the flight. `sendSession` registers a Session submission echo (`session.beginSubmission`) with the delivery mode before serializing, preserving selected image and file order in `pendingSubmissions`; Session derives the placement from that mode and its current running state, so idle sends use the transcript, busy Queue sends use QueueDock, and busy Steer sends use the pending-steering surface. It then yields one paint, encodes images through the browser's native `FileReader` data-URL path, and cites staged file receipts. Command submissions use the same receipts for generic files, so sending `/goal` or `/plan` never reads those browser files again. The prompt reuses the submission `requestId`; queue and history observation by that `rpcId` retires the echo once. Concurrent failures are restored together in submission order until the user edits the restored content; command submissions keep the frozen `submitting` phase. Detached attempts retain their attachment ids through admission and Session scope disposal. An observed retirement immediately exposes each image preview through the durable cache, replaces it with the canonical URL after fetching the admitted attachment, revokes each URL after its use ends, and releases file cards. Selected generic files enter one FIFO background-upload queue; `maxConcurrentFileUploads` defaults to two active Worker transports, the Conversation service retains queued and active operations plus byte progress across Session navigation, and removing a draft skips its queued transfer or aborts its active transport. Where the browser shell exposes `__DSH_HOST_PATHS__` (the Desktop application), dropped or pasted folders and dropped, picked, or pasted non-image files with a real path become `@path` chips; images keep uploading. Drag-and-drop and paste identify directories through the browser entry API; when that API is absent or returns no entry, pasted items retain ordinary file handling. The file picker cannot select directories. References require the `ui-reference` plugin and the original paths to remain readable by the model's file tools. Paths inside the workspace are relative; others remain absolute. The whole batch is validated before insertion, retains source order and selected text, and uses whitespace-separated, closed-quote mentions. A browser without the bridge refuses dropped or pasted folders; a Desktop folder without a reported path is rejected separately. Continuable subagents disable attachment intake and skip local echoes because their transport does not preserve the browser request id.
|
||||
|
||||
@@ -66,6 +66,8 @@ Session 首次绑定或缓存的 Session 成为 current 时,shell 会在渲染
|
||||
|
||||
主 occurrence 的活跃 transcript 只在未被内容覆盖的两侧沟槽中提供正文宽度拖拽条;嵌入式 occurrence 省略这些拖拽条。View 如果绘制进沟槽,只将具体的可见元素提到拖拽条上方;透明的全宽包装层保持在下方,不会占用空白沟槽。该规则要求此元素与 Conversation body 之间不能引入中间堆叠上下文;浏览器场景固定了交付 Chromium 的行为。Chat 将该规则用于表格元素,其限定在阅读列内的工具卡片无需提高层级。指针位于拖拽条上时,滚轮仍会滚动 transcript,Ctrl+滚轮则保留为浏览器缩放手势。粘滞 composer 刻意拥有完整的底部区带,该区域不是宽度调整目标;已捕获的拖拽会将指示线提高到松开为止([拖动手柄样式](src/client/skeleton/ConversationRoot.module.css))。
|
||||
|
||||
宽度拖拽条处理指针移动时,先检查同步的 dragging ref,再确认指针捕获,之后才读取布局、写入样式或调度动画帧。指针处理函数直接更新拖拽指示,不触发 React 状态更新。指示线只在已捕获指针的拖拽期间跟随指针,普通悬停不改变其位置。
|
||||
|
||||
常驻 composer 在无 Session 与有 Session 之间保持挂载。输入空白字符会隐藏占位提示;没有附件的纯空白草稿无法发送。无 Session 时,同一个编辑器表面保持 inert,Workspace picker 连接 blank Session。该表面是 shell 所有的 Lexical 编辑器:引用 chip 是携带 owner 序列化身份的原子 decorator 节点(提交时经 owner codec 展开),已认领的 slash command 保持为带样式的行首文本,文件夹文本引用以图标前缀携带文件夹图形,草稿的剪贴板投影镜像到逐 Session Conversation store。QueueDock 直接从 Session 的 `inbox` 投影读取 `next-turn`,包含从冷状态恢复的消息。Queue 操作通过 scoped `ctx.conversation` service 寻址准确的 queue occurrence;queue 预览经 `ui-primitives` 的共享行内引用投影渲染已发送文本(wire 会话形式折叠为其标签),并按原始附件顺序展示本地或持久化的图片和文件。图片使用缩略图,文件使用紧凑的名称与大小卡片。编辑态展示字面发送文本,持久化缩略图通过会话图片 URL 缓存解析。繁忙时 Enter 行为保存在 Host-backed `ui-conversation` settings namespace。 composer 键盘映射经斜杠流水线裁决触发菜单的按键——Tab 确认高亮补全项(可下钻项则下钻),Escape 与 Shift+Tab 离开菜单且不选定——其余按键交给编辑器自身。 接管键盘的浮层通过 `SessionInput.focus()` 把键盘还回来,该路径走 Lexical 自己的 focus,因此光标回到草稿原来的位置而不是开头。
|
||||
|
||||
默认发送采用乐观提交:Enter 在同一事务里清空草稿、occurrence 表和撤销历史,composer 保持 `plain`,发送作为 detached attempt 运行,发送期间可以继续输入和提交。`sendSession` 在序列化之前用投递模式注册 Session 提交回显(`session.beginSubmission`),并在 `pendingSubmissions` 中保留图片与文件的选择顺序;Session 根据该模式与当前运行状态推导位置,因此空闲发送进入 transcript(文本记录),繁忙时 Queue 进入 QueueDock,繁忙时 Steer 进入 pending-steering 区域。随后让出一帧,图片经浏览器原生 `FileReader` data-URL 路径编码,文件则引用已暂存凭证。命令提交也用同一凭证表示通用文件,因此发送 `/goal` 或 `/plan` 时不会再次读取这些浏览器文件。提示词复用提交 `requestId`;queue 或历史以同一 `rpcId` 被观察后,回显只退休一次。多个并发发送失败时,在用户编辑还原内容之前按提交顺序合并还原;命令提交保持冻结的 `submitting` 阶段。Detached attempt 持有附件 id,直到 admission 完成或 Session scope 销毁。回显以 observed 退休时,durable 图片缓存立即公开每个预览 URL,读取 admitted 附件后用规范化 URL 替换预览,并在各 URL 停止使用后撤销,同时释放文件卡。选中的通用文件进入同一个先进先出的后台上传队列;`maxConcurrentFileUploads` 默认允许两个 Worker transport 同时运行,Conversation 服务在切换 Session 时继续持有排队和运行中的传输操作及字节进度,移除草稿会跳过排队中的传输或中止正在运行的传输。浏览器 shell 暴露 `__DSH_HOST_PATHS__` 时(桌面应用),拖入或粘贴的文件夹以及拖入、选择或粘贴的带真实路径的非图片文件会成为 `@路径` chip;图片仍然上传。拖放和粘贴通过浏览器 entry API 识别目录;该 API 不可用或没有返回 entry 时,粘贴项沿用普通文件处理。文件选择器不能选择目录。引用需要启用 `ui-reference` 插件,原路径也必须仍可由模型的文件工具读取。工作区内的路径使用相对形式,其他路径保留绝对形式。整批文件先校验再插入,保留来源顺序和已选中的文字,引用之间有空白分隔,含空格的路径使用闭合引号。没有该桥的浏览器会拒绝拖入或粘贴的文件夹,桌面端无法获取文件夹路径时单独报错。continuable 子代理禁用附件入口,也不创建本地回显,因为其 transport 不保留浏览器 request id。
|
||||
|
||||
@@ -272,14 +272,14 @@ button.crumb:hover {
|
||||
left: calc(50% + var(--dsh-chat-content-width) / 2 + 24px);
|
||||
}
|
||||
|
||||
/* The glow: a short 2px bar riding the pointer's Y, centered in the strip
|
||||
/* The glow: a short 2px bar following the captured pointer's Y, centered in the strip
|
||||
(29px from the content column), not a full-height rule — a 16px solid core
|
||||
centered on the pointer
|
||||
(published by pointermove as --dsh-width-handle-pointer-y), fading to
|
||||
(published during drag as --dsh-width-handle-pointer-y), fading to
|
||||
transparent over 28px each side (72px total). A solid CORE, not a single
|
||||
solid stop: a lone peak washes out over the fade. The resting scrollbar
|
||||
tint keeps this secondary affordance quiet in both themes. Before the first
|
||||
move the fallback centers the glow at 50% height. */
|
||||
drag move the fallback centers the glow at 50% height; hover leaves its position unchanged. */
|
||||
.widthHandle::after {
|
||||
content: '';
|
||||
position: absolute;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useLayoutEffect, useRef, useState } from 'react'
|
||||
import { useCallback, useLayoutEffect, useRef } from 'react'
|
||||
import type { ConversationWidthControlsProps } from '../contract/slots.ts'
|
||||
import css from './ConversationRoot.module.css'
|
||||
|
||||
@@ -45,7 +45,7 @@ function WidthHandle(props: {
|
||||
onCommit: (width: number) => void
|
||||
onEnd: () => void
|
||||
}) {
|
||||
const [dragging, setDragging] = useState(false)
|
||||
const dragging = useRef(false)
|
||||
const base = useRef(0)
|
||||
const origin = useRef(0)
|
||||
const latest = useRef(0)
|
||||
@@ -68,12 +68,14 @@ function WidthHandle(props: {
|
||||
origin.current = event.clientX
|
||||
latest.current = event.clientX
|
||||
base.current = callbacks.current.onStart()
|
||||
setDragging(true)
|
||||
dragging.current = true
|
||||
event.currentTarget.toggleAttribute('data-dragging', true)
|
||||
}, [])
|
||||
const onPointerMove = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!dragging.current) return
|
||||
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return
|
||||
const box = event.currentTarget.getBoundingClientRect()
|
||||
event.currentTarget.style.setProperty('--dsh-width-handle-pointer-y', `${event.clientY - box.top}px`)
|
||||
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return
|
||||
latest.current = event.clientX
|
||||
frame.current ??= requestAnimationFrame(() => {
|
||||
frame.current = null
|
||||
@@ -81,19 +83,23 @@ function WidthHandle(props: {
|
||||
})
|
||||
}, [])
|
||||
const onPointerUp = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!dragging.current) return
|
||||
if (!event.currentTarget.hasPointerCapture(event.pointerId)) return
|
||||
dragging.current = false
|
||||
event.currentTarget.toggleAttribute('data-dragging', false)
|
||||
event.currentTarget.releasePointerCapture(event.pointerId)
|
||||
cancelFrame()
|
||||
latest.current = event.clientX
|
||||
// A press-only gesture must not overwrite a wider preference with its window-clamped display value.
|
||||
if (latest.current !== origin.current) callbacks.current.onCommit(outwardWidth())
|
||||
setDragging(false)
|
||||
callbacks.current.onEnd()
|
||||
}, [])
|
||||
const onPointerCancel = useCallback(() => {
|
||||
const onPointerCancel = useCallback((event: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!dragging.current) return
|
||||
dragging.current = false
|
||||
event.currentTarget.toggleAttribute('data-dragging', false)
|
||||
// Cancellation abandons persistence and restores the saved width through onEnd.
|
||||
cancelFrame()
|
||||
setDragging(false)
|
||||
callbacks.current.onEnd()
|
||||
}, [])
|
||||
const onWheel = useCallback((event: React.WheelEvent<HTMLDivElement>) => {
|
||||
@@ -112,7 +118,6 @@ function WidthHandle(props: {
|
||||
className={css.widthHandle}
|
||||
data-side={props.side}
|
||||
data-width-handle={props.side}
|
||||
data-dragging={dragging || undefined}
|
||||
onPointerDown={onPointerDown}
|
||||
onPointerMove={onPointerMove}
|
||||
onPointerUp={onPointerUp}
|
||||
|
||||
@@ -729,7 +729,10 @@ describe('ConversationRoot resident composer', () => {
|
||||
// Dragging the right handle outward by 25px widens by 2×25 = 50 → 970,
|
||||
// inside both bounds (max = 1600 − 176 = 1424 keeps the handles on-column).
|
||||
fireEvent.pointerDown(handle, { pointerId: 1, clientX: 800, clientY: 300 })
|
||||
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 825, clientY: 300 })
|
||||
expect(handle.style.getPropertyValue('--dsh-width-handle-pointer-y')).toBe('300px')
|
||||
fireEvent.pointerUp(handle, { pointerId: 1, clientX: 825, clientY: 300 })
|
||||
expect(handle.hasAttribute('data-dragging')).toBe(false)
|
||||
expect(root.style.getPropertyValue('--dsh-chat-user-width')).toBe('970px')
|
||||
expect(localStorage.getItem('dsh.conversation.contentWidth')).toBe('970')
|
||||
// Window shrinks: the displayed width re-clamps (900 − 176 = 724) but the
|
||||
@@ -791,6 +794,28 @@ describe('ConversationRoot resident composer', () => {
|
||||
expect(nestedScrollBy).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not check capture, measure, style, or schedule width-handle moves before dragging', () => {
|
||||
const b = mount(sessionSnapshotOf())
|
||||
const handle = b.view.container.querySelector('[data-width-handle="right"]') as HTMLElement
|
||||
const capture = vi.fn(() => false)
|
||||
Object.defineProperty(handle, 'hasPointerCapture', { value: capture })
|
||||
const measure = vi.spyOn(handle, 'getBoundingClientRect')
|
||||
const style = vi.spyOn(handle.style, 'setProperty')
|
||||
const schedule = vi.spyOn(globalThis, 'requestAnimationFrame')
|
||||
try {
|
||||
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 800, clientY: 300 })
|
||||
fireEvent.pointerMove(handle, { pointerId: 1, clientX: 802, clientY: 302 })
|
||||
expect(capture).not.toHaveBeenCalled()
|
||||
expect(measure).not.toHaveBeenCalled()
|
||||
expect(style).not.toHaveBeenCalled()
|
||||
expect(schedule).not.toHaveBeenCalled()
|
||||
} finally {
|
||||
schedule.mockRestore()
|
||||
style.mockRestore()
|
||||
measure.mockRestore()
|
||||
}
|
||||
})
|
||||
|
||||
it('starts width dragging only from the primary pointer button', () => {
|
||||
const b = mount(sessionSnapshotOf())
|
||||
const handle = b.view.container.querySelector('[data-width-handle="right"]') as HTMLElement
|
||||
@@ -805,6 +830,9 @@ describe('ConversationRoot resident composer', () => {
|
||||
fireEvent.pointerDown(handle, { pointerId: 2, button: 0, clientX: 800, clientY: 300 })
|
||||
expect(handle.hasAttribute('data-dragging')).toBe(true)
|
||||
fireEvent.pointerCancel(handle, { pointerId: 2 })
|
||||
expect(handle.hasAttribute('data-dragging')).toBe(false)
|
||||
fireEvent.pointerMove(handle, { pointerId: 2, clientX: 825, clientY: 300 })
|
||||
expect(handle.style.getPropertyValue('--dsh-width-handle-pointer-y')).toBe('')
|
||||
})
|
||||
|
||||
it('hero phase renders no width handles (no transcript to size)', () => {
|
||||
|
||||
Reference in new issue
Block a user