Merge #4046 into stage-mj
This commit is contained in:
@@ -1288,8 +1288,8 @@ $('modelSelect').onchange=async()=>{
|
||||
}
|
||||
};
|
||||
$('msg').addEventListener('input',()=>{
|
||||
autoResize();
|
||||
updateSendBtn();
|
||||
scheduleComposerAutoResize();
|
||||
// Persist composer draft to server (debounced in _saveComposerDraft).
|
||||
const sid = S && S.session && S.session.session_id;
|
||||
if (sid && typeof _saveComposerDraft === 'function') {
|
||||
|
||||
@@ -3868,7 +3868,25 @@ function transcript(){
|
||||
return lines.join('\n');
|
||||
}
|
||||
|
||||
function autoResize(){const el=$('msg');el.style.height='auto';el.style.height=Math.min(el.scrollHeight,200)+'px';updateSendBtn();}
|
||||
let _composerAutoResizeRaf=0;
|
||||
function autoResize(){
|
||||
if(_composerAutoResizeRaf && typeof cancelAnimationFrame==='function'){
|
||||
cancelAnimationFrame(_composerAutoResizeRaf);
|
||||
_composerAutoResizeRaf=0;
|
||||
}
|
||||
const el=$('msg');
|
||||
el.style.height='auto';
|
||||
el.style.height=Math.min(el.scrollHeight,200)+'px';
|
||||
updateSendBtn();
|
||||
}
|
||||
function scheduleComposerAutoResize(){
|
||||
if(typeof requestAnimationFrame!=='function'){autoResize();return;}
|
||||
if(_composerAutoResizeRaf) return;
|
||||
_composerAutoResizeRaf=requestAnimationFrame(()=>{
|
||||
_composerAutoResizeRaf=0;
|
||||
autoResize();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// ── YOLO mode state ──
|
||||
|
||||
27
tests/test_issue4042_typing_lag_autoresize.py
Normal file
27
tests/test_issue4042_typing_lag_autoresize.py
Normal file
@@ -0,0 +1,27 @@
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
REPO = Path(__file__).resolve().parents[1]
|
||||
MESSAGES_JS = (REPO / "static" / "messages.js").read_text(encoding="utf-8")
|
||||
BOOT_JS = (REPO / "static" / "boot.js").read_text(encoding="utf-8")
|
||||
|
||||
|
||||
def test_composer_autoresize_is_single_flight_per_frame():
|
||||
assert "let _composerAutoResizeRaf=0;" in MESSAGES_JS
|
||||
assert "function scheduleComposerAutoResize()" in MESSAGES_JS
|
||||
assert "if(typeof requestAnimationFrame!=='function'){autoResize();return;}" in MESSAGES_JS
|
||||
assert "if(_composerAutoResizeRaf) return;" in MESSAGES_JS
|
||||
assert "_composerAutoResizeRaf=requestAnimationFrame(()=>{" in MESSAGES_JS
|
||||
assert "cancelAnimationFrame(_composerAutoResizeRaf);" in MESSAGES_JS
|
||||
assert "_composerAutoResizeRaf=0;" in MESSAGES_JS
|
||||
assert "autoResize();" in MESSAGES_JS
|
||||
|
||||
|
||||
def test_composer_input_listener_uses_scheduler_instead_of_direct_reflow():
|
||||
start = BOOT_JS.index("$('msg').addEventListener('input',()=>{")
|
||||
end = BOOT_JS.index("// Persist composer draft to server", start)
|
||||
listener = BOOT_JS[start:end]
|
||||
|
||||
assert "scheduleComposerAutoResize();" in listener
|
||||
assert "autoResize();" not in listener
|
||||
assert "updateSendBtn();" in listener
|
||||
Reference in New Issue
Block a user