From ee8b2651731144cbdefcb4136bfd07abb28ccc59 Mon Sep 17 00:00:00 2001 From: BlakeNeko Date: Sat, 15 Nov 2025 22:13:59 +0800 Subject: [PATCH] feat: Preserving the previous cursor position --- web/js/auto-formatter.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/web/js/auto-formatter.js b/web/js/auto-formatter.js index 839cc15..6554ed0 100644 --- a/web/js/auto-formatter.js +++ b/web/js/auto-formatter.js @@ -58,6 +58,11 @@ export function formatTextareaOnBlur(textarea) { const formattedText = formatPromptText(originalText); if (originalText !== formattedText) { - textarea.setRangeText(formattedText, 0, originalText.length, 'end'); + const cursorPos = textarea.selectionStart; + textarea.value = formattedText; + + // Try to preserve cursor position + const newCursorPos = Math.min(cursorPos, formattedText.length); + textarea.setSelectionRange(newCursorPos, newCursorPos); } }