From 2be92e1106e0c69ea975af99e198fb5fb0985cee Mon Sep 17 00:00:00 2001 From: kicer Date: Fri, 13 Nov 2026 16:16:03 +0800 Subject: [PATCH] =?UTF-8?q?perf(ui):=20=E9=A2=84=E8=A7=88=E6=A0=8F?= =?UTF-8?q?=E6=8B=96=E6=8B=BD=E8=B0=83=E5=AE=BD=E6=94=B9=E4=B8=BA=E6=AF=8F?= =?UTF-8?q?=E5=B8=A7=E8=90=BD=E5=80=BC=EF=BC=8C=E6=8B=96=E5=8A=A8=E6=9C=9F?= =?UTF-8?q?=E9=97=B4=E5=9C=88=E4=BD=8F=E9=87=8D=E6=8E=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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)。 --- app/server/public/css/style.css | 8 ++++++-- app/server/public/js/preview.js | 18 ++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/app/server/public/css/style.css b/app/server/public/css/style.css index 2c2e05b..1dbc77b 100644 --- a/app/server/public/css/style.css +++ b/app/server/public/css/style.css @@ -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; } diff --git a/app/server/public/js/preview.js b/app/server/public/js/preview.js index 63c9c5c..fa84970 100644 --- a/app/server/public/js/preview.js +++ b/app/server/public/js/preview.js @@ -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);