1
- import { Scanner , Token , ScannerState } from './clojure-lexer' ;
2
- import { LispTokenCursor } from './token-cursor' ;
1
+ import { isUndefined , max , min } from 'lodash' ;
3
2
import { deepEqual as equal } from '../util/object' ;
4
- import { isUndefined } from 'lodash' ;
3
+ import { Scanner , ScannerState , Token } from './clojure-lexer' ;
4
+ import { LispTokenCursor } from './token-cursor' ;
5
5
6
6
let scanner : Scanner ;
7
7
@@ -84,6 +84,7 @@ export type ModelEditOptions = {
84
84
undoStopBefore ?: boolean ;
85
85
formatDepth ?: number ;
86
86
skipFormat ?: boolean ;
87
+ selections ?: ModelEditSelection [ ] ;
87
88
selection ?: ModelEditSelection ;
88
89
} ;
89
90
@@ -107,11 +108,14 @@ export interface EditableDocument {
107
108
readonly selectionLeft : number ;
108
109
readonly selectionRight : number ;
109
110
selection : ModelEditSelection ;
111
+ selections : ModelEditSelection [ ] ;
110
112
model : EditableModel ;
113
+ selectionsStack : ModelEditSelection [ ] [ ] ;
111
114
selectionStack : ModelEditSelection [ ] ;
112
115
getTokenCursor : ( offset ?: number , previous ?: boolean ) => LispTokenCursor ;
113
116
insertString : ( text : string ) => void ;
114
- getSelectionText : ( ) => string ;
117
+ getSelectionText : ( index ?: number ) => string ;
118
+ getSelectionsText : ( ) => string [ ] ;
115
119
delete : ( ) => Thenable < boolean > ;
116
120
backspace : ( ) => Thenable < boolean > ;
117
121
}
@@ -548,6 +552,8 @@ export class StringDocument implements EditableDocument {
548
552
549
553
model : LineInputModel = new LineInputModel ( 1 , this ) ;
550
554
555
+ selectionsStack : ModelEditSelection [ ] [ ] = [ ] ;
556
+ selections : ModelEditSelection [ ] = [ ] ;
551
557
selectionStack : ModelEditSelection [ ] = [ ] ;
552
558
553
559
getTokenCursor ( offset ?: number , previous ?: boolean ) : LispTokenCursor {
@@ -558,23 +564,35 @@ export class StringDocument implements EditableDocument {
558
564
return this . model . getTokenCursor ( offset ) ;
559
565
}
560
566
567
+ getSelectionsText : ( ) => string [ ] ;
561
568
insertString ( text : string ) {
562
569
this . model . insertString ( 0 , text ) ;
563
570
}
564
571
565
- getSelectionText : ( ) => string ;
566
-
567
572
delete ( ) {
568
- const p = this . selectionLeft ;
569
- return this . model . edit ( [ new ModelEdit ( 'deleteRange' , [ p , 1 ] ) ] , {
570
- selection : new ModelEditSelection ( p ) ,
573
+ const edits = [ ] ;
574
+ const selections = [ ] ;
575
+ this . selections . forEach ( ( { anchor : p } ) => {
576
+ edits . push ( new ModelEdit ( 'deleteRange' , [ p , 1 ] ) ) ;
577
+ selections . push ( new ModelEditSelection ( p ) ) ;
578
+ } ) ;
579
+
580
+ return this . model . edit ( edits , {
581
+ selections,
571
582
} ) ;
572
583
}
584
+ getSelectionText : ( ) => string ;
573
585
574
586
backspace ( ) {
575
- const p = this . selectionLeft ;
576
- return this . model . edit ( [ new ModelEdit ( 'deleteRange' , [ p - 1 , 1 ] ) ] , {
577
- selection : new ModelEditSelection ( p - 1 ) ,
587
+ const edits = [ ] ;
588
+ const selections = [ ] ;
589
+ this . selections . forEach ( ( { anchor : p } ) => {
590
+ edits . push ( new ModelEdit ( 'deleteRange' , [ p - 1 , 1 ] ) ) ;
591
+ selections . push ( new ModelEditSelection ( p - 1 ) ) ;
592
+ } ) ;
593
+
594
+ return this . model . edit ( edits , {
595
+ selections,
578
596
} ) ;
579
597
}
580
598
}
0 commit comments