Skip to content

Commit 923a7d7

Browse files
authored
fix: prevent cursor jumping to end of textarea in NewSessionModal (#17)
1 parent 61273ac commit 923a7d7

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

staged/src/lib/NewSessionModal.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
}
4646
});
4747
48-
// Focus textarea on mount
48+
// Focus textarea on mount (one-time)
4949
$effect(() => {
5050
if (textareaEl) {
51-
textareaEl.focus();
52-
if (prompt) {
53-
textareaEl.selectionStart = textareaEl.selectionEnd = prompt.length;
54-
}
51+
const el = textareaEl;
52+
// Read length from the DOM element to avoid tracking `prompt` reactively,
53+
// which would re-run this effect on every keystroke and force the cursor
54+
// to the end of the buffer.
55+
el.focus();
56+
el.selectionStart = el.selectionEnd = el.value.length;
5557
}
5658
});
5759

0 commit comments

Comments
 (0)