@@ -656,38 +656,49 @@ function listStyle(textarea: HTMLTextAreaElement, style: StyleArgs): SelectionRa
656656 // Select whole line
657657 expandSelectionToLine ( textarea )
658658
659- const prefix = '- '
659+ const prefix = ( index : number ) : string => {
660+ if ( style . unorderedList ) {
661+ return '- '
662+ } else if ( style . orderedList ) {
663+ return `${ index + 1 } . `
664+ }
665+ return ''
666+ }
660667
661668 let selectedText = textarea . value . slice ( textarea . selectionStart , textarea . selectionEnd )
662669
663670 const undoOrderedListResult = undoOrderedListStyle ( selectedText )
664671 const undoUnorderedListResult = undoUnorderedListStyle ( undoOrderedListResult . text )
665672
666673 if ( undoOrderedListResult . processed || undoUnorderedListResult . processed ) {
667- if ( noInitialSelection ) {
668- selectionStart = Math . max ( selectionStart - prefix . length , 0 )
669- selectionEnd = selectionStart
670- } else {
671- selectionStart = Math . max ( selectionStart - prefix . length , 0 )
672- selectionEnd = selectionEnd + prefix . length // * lines.length
673- }
674+ // if (noInitialSelection) {
675+ // selectionStart = Math.max(selectionStart - prefix.length, 0)
676+ // selectionEnd = selectionStart
677+ // } else {
678+ // selectionStart = Math.max(selectionStart - prefix.length, 0)
679+ // selectionEnd = selectionEnd + prefix.length // * lines.length
680+ // }
674681 return { text : undoUnorderedListResult . text , selectionStart, selectionEnd}
675682 }
676683
677684 selectedText = undoUnorderedListResult . text
678685
679686 const lines = selectedText . split ( '\n' ) . map ( ( value , index ) => {
680- return `${ prefix } ${ value } `
687+ return `${ prefix ( index ) } ${ value } `
681688 } )
682689
690+ const totalPrefixLength = lines . reduce ( ( previousValue , currentValue , currentIndex ) => {
691+ return previousValue + prefix ( currentIndex ) . length
692+ } , 0 )
693+
683694 const { newlinesToAppend, newlinesToPrepend} = newlinesToSurroundSelectedText ( textarea )
684695
685696 if ( noInitialSelection ) {
686- selectionStart = Math . max ( selectionStart + prefix . length + newlinesToAppend . length , 0 )
697+ selectionStart = Math . max ( selectionStart + prefix ( 0 ) . length + newlinesToAppend . length , 0 )
687698 selectionEnd = selectionStart
688699 } else {
689- selectionStart = Math . max ( selectionStart + prefix . length + newlinesToAppend . length , 0 )
690- selectionEnd = selectionEnd + newlinesToAppend . length + prefix . length * lines . length
700+ selectionStart = Math . max ( selectionStart + prefix ( 0 ) . length + newlinesToAppend . length , 0 )
701+ selectionEnd = selectionEnd + newlinesToAppend . length + totalPrefixLength
691702 }
692703
693704 const text = newlinesToAppend + lines . join ( '\n' ) + newlinesToPrepend
0 commit comments