perf(ui): 预览栏拖拽调宽改为每帧落值,拖动期间圈住重排

pointermove 每来一次就写 --pv-w:这个变量同时驱动 #pv-pane 宽度、#app 的 width 与
margin-left、#toast 的 left,等于每个鼠标事件都让整棵会话 DOM 重新布局、消息文字重新折行,
长会话下明显卡顿,鼠标 120Hz 时一帧还不止一次。

改成 pointermove 只记 lastX,rAF 里落一次值;pointerup 若还有挂起的帧先取消再补一次,
保证落点准确。拖动期间 body.pv-resizing 下:#app 关掉 pointer-events(图片/链接的 HTML5
拖拽不会再冒出来)、#chat-view 与 #pv-pane 各加 contain,把重排重绘圈在列内。

选中文字是同一处实现的两个缺口:pointerdown 没有 preventDefault,按下那一刻就可能开始
拖选;手柄只有 6px,点偏到会话区就完全没进 resizer 的 pointerdown。前者补上,后者把热区
放宽到 10px(hover 透明度同步从 .3 调到 .25)。
This commit is contained in:
2026-11-13 16:16:03 +08:00
parent f5099345d0
commit 2be92e1106
2 changed files with 20 additions and 6 deletions
+6 -2
View File
@@ -1656,9 +1656,13 @@ label.icon-btn { cursor: pointer; }
/* ---------- preview pane v2: drag resize / info card / plain text ---------- */
/* 拖拽调宽的手柄:预览在左半侧,所以手柄在它的右缘(与会话列的分界) */
.pv-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 6px; cursor: col-resize; z-index: 6; touch-action: none; }
.pv-resizer:hover, .pv-resizer:active { background: var(--active); opacity: .3; }
.pv-resizer { position: absolute; right: 0; top: 0; bottom: 0; width: 10px; cursor: col-resize; z-index: 6; touch-action: none; }
.pv-resizer:hover, .pv-resizer:active { background: var(--active); opacity: .25; }
body.pv-resizing { cursor: col-resize; user-select: none; }
/* 拖动期间把重排/重绘圈在各自列里:会话列宽度跟着变,不 contain 就是整页重排 */
body.pv-resizing #app { pointer-events: none; }
body.pv-resizing #chat-view { contain: paint; }
body.pv-resizing #pv-pane { contain: layout paint; }
body.pv-resizing #pv-pane iframe { pointer-events: none; }
.pv-plain { width: 100%; }
.pv-pre { width: 100%; max-width: 920px; margin: 0 auto; padding: 14px 20px 40px; font: 12.5px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-all; }
+14 -4
View File
@@ -789,21 +789,31 @@ window.matchMedia('(min-width: 960px)').addEventListener('change', () => { if (!
const h = document.createElement('div');
h.className = 'pv-resizer';
pane.appendChild(h);
let st = null;
let st = null; // { x: 起始 clientX, w: 起始宽度, lastX: 最新 clientX }
let rafId = 0;
// 改 --pv-w 会带着 #app 的 width/margin 一起重排(会话里的文字跟着重新折行),
// 一帧可能来十几个 pointermove,所以只在 rAF 里落一次值。
function commit() {
if (!st) return;
document.documentElement.style.setProperty('--pv-w', clamp(st.w + (st.lastX - st.x)) + 'px');
}
h.addEventListener('pointerdown', (e) => {
st = { x: e.clientX, w: pane.offsetWidth || clamp(window.innerWidth * 0.5) };
e.preventDefault(); // 从按下这一刻就掐掉拖选,否则会顺手选中一大片消息文字
st = { x: e.clientX, w: pane.offsetWidth || clamp(window.innerWidth * 0.5), lastX: e.clientX };
try { h.setPointerCapture(e.pointerId); } catch (_) {}
document.body.classList.add('pv-resizing');
});
h.addEventListener('pointermove', (e) => {
if (!st) return;
document.documentElement.style.setProperty('--pv-w', clamp(st.w + (e.clientX - st.x)) + 'px');
st.lastX = e.clientX;
if (!rafId) rafId = requestAnimationFrame(() => { rafId = 0; commit(); });
});
function end() {
if (!st) return;
if (rafId) { cancelAnimationFrame(rafId); rafId = 0; commit(); } // 把最后一帧补上
const w = pane.offsetWidth;
st = null;
document.body.classList.remove('pv-resizing');
const w = pane.offsetWidth;
if (w) localStorage.setItem('pv-w', String(w));
}
h.addEventListener('pointerup', end);