Skip to content

Commit acaa749

Browse files
committed
Put cursor at the end of line when there was no selection
1 parent ac59a92 commit acaa749

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ function multilineStyle(textarea: HTMLTextAreaElement, arg: StyleArgs) {
480480

481481
function orderedList(textarea: HTMLTextAreaElement): SelectionRange {
482482
const orderedListRegex = /^\d+\.\s+/
483+
const noInitialSelection = textarea.selectionStart === textarea.selectionEnd
483484
let selectionEnd
484485
let selectionStart
485486
let text = textarea.value.slice(textarea.selectionStart, textarea.selectionEnd)
@@ -506,6 +507,7 @@ function orderedList(textarea: HTMLTextAreaElement): SelectionRange {
506507
const {newlinesToAppend, newlinesToPrepend} = newlinesToSurroundSelectedText(textarea)
507508
selectionStart = textarea.selectionStart + newlinesToAppend.length
508509
selectionEnd = selectionStart + text.length
510+
if (noInitialSelection) selectionStart = selectionEnd
509511
text = newlinesToAppend + text + newlinesToPrepend
510512
}
511513

0 commit comments

Comments
 (0)