From bb26eb5af941e387e77198111fa9232d9ad51590 Mon Sep 17 00:00:00 2001 From: nvms Date: Sat, 9 Dec 2023 10:14:56 -0500 Subject: [PATCH] bug: bad cursor placement after pressing enter --- webview/src/components/GrowingTextarea.svelte | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webview/src/components/GrowingTextarea.svelte b/webview/src/components/GrowingTextarea.svelte index defab2b..3692091 100644 --- a/webview/src/components/GrowingTextarea.svelte +++ b/webview/src/components/GrowingTextarea.svelte @@ -32,7 +32,11 @@ dispatch("submit", value); } else if (!event.shiftKey && enterCreatesNewLine) { event.preventDefault(); - value += "\n"; + const selectionStart = event.target.selectionStart; + const selectionEnd = event.target.selectionEnd; + value = value.slice(0, selectionStart) + "\n" + value.slice(selectionEnd); + event.target.value = value; // Set the textarea value to the updated value + event.target.selectionStart = event.target.selectionEnd = selectionStart + 1; tick().then(() => { autoGrow(); });