fix: move setComposerCursor outside rAF to prevent stale trigger flash
setComposerCursor was deferred inside requestAnimationFrame while setPrompt was called synchronously. This caused an intermediate render where composerTrigger was computed with the new prompt text but the old cursor position, briefly reopening the command menu with incorrect results. Moving setComposerCursor alongside setPrompt ensures both states update in the same render cycle.
This commit is contained in:
1 parent
0371dc90b9
commit
583765b883
1 file changed
+1
-1
@@ -1246,12 +1246,12 @@ export default function ChatView() {
|
||||
const next = replaceTextRange(promptRef.current, rangeStart, rangeEnd, replacement);
|
||||
promptRef.current = next.text;
|
||||
setPrompt(next.text);
|
||||
setComposerCursor(next.cursor);
|
||||
window.requestAnimationFrame(() => {
|
||||
const textarea = textareaRef.current;
|
||||
if (!textarea) return;
|
||||
textarea.focus();
|
||||
textarea.setSelectionRange(next.cursor, next.cursor);
|
||||
setComposerCursor(next.cursor);
|
||||
});
|
||||
},
|
||||
[],
|
||||
|
||||
Reference in new issue
Block a user