feat: Preserving the previous cursor position

This commit is contained in:
BlakeNeko
2025-11-15 22:13:59 +08:00
parent 80d254c6b4
commit ee8b265173
+6 -1
View File
@@ -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);
}
}