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); } }