@@ -448,17 +448,6 @@ function expandSelectionToLine(textarea: HTMLTextAreaElement) {
448
448
}
449
449
}
450
450
451
- function selectionIndexForLine ( lines : string [ ] , line : number ) : SelectionRange | null {
452
- let counter = 0
453
- for ( let index = 0 ; index < lines . length ; index ++ ) {
454
- if ( index === line ) {
455
- return { selectionStart : counter , selectionEnd : counter + lines [ index ] . length , text : '' }
456
- }
457
- counter += lines [ index ] . length + 1
458
- }
459
- return null
460
- }
461
-
462
451
function expandSelectedText (
463
452
textarea : HTMLTextAreaElement ,
464
453
prefixToUse : string ,
@@ -723,46 +712,6 @@ function listStyle(textarea: HTMLTextAreaElement, style: StyleArgs): SelectionRa
723
712
return { text, selectionStart, selectionEnd}
724
713
}
725
714
726
- function orderedList ( textarea : HTMLTextAreaElement ) : SelectionRange {
727
- const orderedListRegex = / ^ \d + \. \s + /
728
- const noInitialSelection = textarea . selectionStart === textarea . selectionEnd
729
- let selectionEnd
730
- let selectionStart
731
- let text = textarea . value . slice ( textarea . selectionStart , textarea . selectionEnd )
732
- let textToUnstyle = text
733
- let lines = text . split ( '\n' )
734
- let startOfLine , endOfLine
735
- if ( noInitialSelection ) {
736
- const linesBefore = textarea . value . slice ( 0 , textarea . selectionStart ) . split ( / \n / )
737
- startOfLine = textarea . selectionStart - linesBefore [ linesBefore . length - 1 ] . length
738
- endOfLine = wordSelectionEnd ( textarea . value , textarea . selectionStart , true )
739
- textToUnstyle = textarea . value . slice ( startOfLine , endOfLine )
740
- }
741
- const linesToUnstyle = textToUnstyle . split ( '\n' )
742
- const undoStyling = linesToUnstyle . every ( line => orderedListRegex . test ( line ) )
743
-
744
- if ( undoStyling ) {
745
- lines = linesToUnstyle . map ( line => line . replace ( orderedListRegex , '' ) )
746
- text = lines . join ( '\n' )
747
- if ( noInitialSelection && startOfLine && endOfLine ) {
748
- const lengthDiff = linesToUnstyle [ 0 ] . length - lines [ 0 ] . length
749
- selectionStart = selectionEnd = textarea . selectionStart - lengthDiff
750
- textarea . selectionStart = startOfLine
751
- textarea . selectionEnd = endOfLine
752
- }
753
- } else {
754
- lines = numberedLines ( lines )
755
- text = lines . join ( '\n' )
756
- const { newlinesToAppend, newlinesToPrepend} = newlinesToSurroundSelectedText ( textarea )
757
- selectionStart = textarea . selectionStart + newlinesToAppend . length
758
- selectionEnd = selectionStart + text . length
759
- if ( noInitialSelection ) selectionStart = selectionEnd
760
- text = newlinesToAppend + text + newlinesToPrepend
761
- }
762
-
763
- return { text, selectionStart, selectionEnd}
764
- }
765
-
766
715
interface StyleArgs {
767
716
prefix : string
768
717
suffix : string
@@ -778,18 +727,6 @@ interface StyleArgs {
778
727
trimFirst : boolean
779
728
}
780
729
781
- function numberedLines ( lines : string [ ] ) {
782
- let i
783
- let len
784
- let index
785
- const results = [ ]
786
- for ( index = i = 0 , len = lines . length ; i < len ; index = ++ i ) {
787
- const line = lines [ index ]
788
- results . push ( `${ index + 1 } . ${ line } ` )
789
- }
790
- return results
791
- }
792
-
793
730
function applyStyle ( button : Element , stylesToApply : Style ) {
794
731
const toolbar = button . closest ( 'markdown-toolbar' )
795
732
if ( ! ( toolbar instanceof MarkdownToolbarElement ) ) return
0 commit comments