fix textarea newline handle (#32966)

- Fix cursor position if input newline on middle of lines
- ~Increment number if numbered list~


![image](https://github.com/user-attachments/assets/bcfe2625-11a8-4ea4-9a71-b7ecfe81b2e0)

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
metiftikci 2024-12-25 08:03:43 +03:00 committed by GitHub
parent abaeae0b9c
commit 1a7591d7f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 5 deletions

View file

@ -92,6 +92,7 @@ function handleNewline(textarea: HTMLTextAreaElement, e: Event) {
if (!line) {
// clear current line if we only have i.e. '1. ' and the user presses enter again to finish creating a list
textarea.value = value.slice(0, lineStart) + value.slice(lineEnd);
textarea.setSelectionRange(selStart - prefix.length, selStart - prefix.length);
} else {
// start a new line with the same indention and prefix
let newPrefix = prefix;