fix(chat): 输入框撑高时消息流狂跳

#chat-view 是 flex:1,高度 = 容器 − 输入区。打字时 autosize() 把 textarea 从一行
撑到两行,输入区变高、chat-view 变矮,贴底的 scrollTop 被浏览器 clamp;下一帧
流式 delta 又 scrollBottom() 拉回去,两边来回拉扯,正在输出的思考面板看起来在
视口里上下狂跳。

修法:autosize() 末尾补一次 maybeAutoScroll()。关键是改高度和补滚动在同一个 JS
任务里,浏览器合并成一次布局,中间态不会渲染出来;用户上翻看历史时 userPaused
为真,不会强制拉回底部。
This commit is contained in:
2026-11-23 07:16:40 +08:00
parent 26ae9a4034
commit 96b2c3a1a5
+8 -1
View File
@@ -2,7 +2,14 @@
'use strict';
// ---------- 输入区 ----------
const ta = $('msg-input');
function autosize() { ta.style.height = 'auto'; ta.style.height = Math.min(ta.scrollHeight, 120) + 'px'; }
// 输入框高度一变,#chat-view(flex:1)的 clientHeight 跟着变:贴底时浏览器会把 scrollTop
// 自动 clamp,下一帧流式 delta 又 scrollBottom 拉回去,两边打架就是「打字时消息狂跳」。
// 同一个 JS 任务里补一次贴底,浏览器合并成一次布局,中间态不会渲染出来。
function autosize() {
ta.style.height = 'auto';
ta.style.height = Math.min(ta.scrollHeight, 120) + 'px';
if (typeof maybeAutoScroll === 'function') maybeAutoScroll();
}
// 输入内容变化直接影响发送键两态:运行中一旦有字就恢复「发送」(可插话),清空后又变回「停止」
ta.addEventListener('input', () => { autosize(); updateSendBtn(); });
// 触屏设备(手机/平板)上:Enter 走默认行为(插入 \n),发消息靠发送按钮,