File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -484,13 +484,27 @@ function orderedList(textarea: HTMLTextAreaElement): SelectionRange {
484
484
let selectionEnd
485
485
let selectionStart
486
486
let text = textarea . value . slice ( textarea . selectionStart , textarea . selectionEnd )
487
+ let textToUnstyle = text
487
488
let lines = text . split ( '\n' )
488
-
489
- const undoStyling = lines . every ( line => orderedListRegex . test ( line ) )
489
+ let startOfLine , endOfLine
490
+ if ( noInitialSelection ) {
491
+ const linesBefore = textarea . value . slice ( 0 , textarea . selectionStart ) . split ( / \n / )
492
+ startOfLine = textarea . selectionStart - linesBefore [ linesBefore . length - 1 ] . length
493
+ endOfLine = wordSelectionEnd ( textarea . value , textarea . selectionStart , true )
494
+ textToUnstyle = textarea . value . slice ( startOfLine , endOfLine )
495
+ }
496
+ const linesToUnstyle = textToUnstyle . split ( '\n' )
497
+ const undoStyling = linesToUnstyle . every ( line => orderedListRegex . test ( line ) )
490
498
491
499
if ( undoStyling ) {
492
- lines = lines . map ( line => line . replace ( orderedListRegex , '' ) )
500
+ lines = linesToUnstyle . map ( line => line . replace ( orderedListRegex , '' ) )
493
501
text = lines . join ( '\n' )
502
+ if ( noInitialSelection && startOfLine && endOfLine ) {
503
+ const lengthDiff = linesToUnstyle [ 0 ] . length - lines [ 0 ] . length
504
+ selectionStart = selectionEnd = textarea . selectionStart - lengthDiff
505
+ textarea . selectionStart = startOfLine
506
+ textarea . selectionEnd = endOfLine
507
+ }
494
508
} else {
495
509
lines = ( function ( ) {
496
510
let i
You can’t perform that action at this time.
0 commit comments