1
- import { includes } from 'lodash' ;
2
1
import { validPair } from './clojure-lexer' ;
3
2
import { ModelEdit , EditableDocument , ModelEditSelection } from './model' ;
4
3
import { LispTokenCursor } from './token-cursor' ;
@@ -16,8 +15,8 @@ import { LispTokenCursor } from './token-cursor';
16
15
export function killRange (
17
16
doc : EditableDocument ,
18
17
range : [ number , number ] ,
19
- start = doc . selectionLeft ,
20
- end = doc . selectionRight
18
+ start = doc . selection . anchor ,
19
+ end = doc . selection . active
21
20
) {
22
21
const [ left , right ] = [ Math . min ( ...range ) , Math . max ( ...range ) ] ;
23
22
void doc . model . edit ( [ new ModelEdit ( 'deleteRange' , [ left , right - left , [ start , end ] ] ) ] , {
@@ -86,7 +85,7 @@ export function selectBackwardDownSexp(doc: EditableDocument) {
86
85
}
87
86
88
87
export function selectForwardUpSexp ( doc : EditableDocument ) {
89
- selectRangeForward ( doc , rangeToForwardUpList ( doc , doc . selectionRight ) ) ;
88
+ selectRangeForward ( doc , rangeToForwardUpList ( doc , doc . selection . active ) ) ;
90
89
}
91
90
92
91
export function selectBackwardUpSexp ( doc : EditableDocument ) {
@@ -98,7 +97,7 @@ export function selectBackwardUpSexp(doc: EditableDocument) {
98
97
}
99
98
100
99
export function selectCloseList ( doc : EditableDocument ) {
101
- selectRangeForward ( doc , rangeToForwardList ( doc , doc . selectionRight ) ) ;
100
+ selectRangeForward ( doc , rangeToForwardList ( doc , doc . selection . active ) ) ;
102
101
}
103
102
104
103
export function selectOpenList ( doc : EditableDocument ) {
@@ -159,7 +158,7 @@ export function backwardSexpRange(
159
158
160
159
export function forwardListRange (
161
160
doc : EditableDocument ,
162
- start : number = doc . selectionRight
161
+ start : number = doc . selection . active
163
162
) : [ number , number ] {
164
163
const cursor = doc . getTokenCursor ( start ) ;
165
164
cursor . forwardList ( ) ;
@@ -168,7 +167,7 @@ export function forwardListRange(
168
167
169
168
export function backwardListRange (
170
169
doc : EditableDocument ,
171
- start : number = doc . selectionRight
170
+ start : number = doc . selection . active
172
171
) : [ number , number ] {
173
172
const cursor = doc . getTokenCursor ( start ) ;
174
173
cursor . backwardList ( ) ;
@@ -358,8 +357,8 @@ export function wrapSexpr(
358
357
doc : EditableDocument ,
359
358
open : string ,
360
359
close : string ,
361
- start : number = doc . selectionLeft ,
362
- end : number = doc . selectionRight ,
360
+ start : number = doc . selection . anchor ,
361
+ end : number = doc . selection . active ,
363
362
options = { skipFormat : false }
364
363
) : Thenable < boolean > {
365
364
const cursor = doc . getTokenCursor ( end ) ;
@@ -407,8 +406,8 @@ export function rewrapSexpr(
407
406
doc : EditableDocument ,
408
407
open : string ,
409
408
close : string ,
410
- start : number = doc . selectionLeft ,
411
- end : number = doc . selectionRight
409
+ start : number = doc . selection . anchor ,
410
+ end : number = doc . selection . active
412
411
) : Thenable < boolean > {
413
412
const cursor = doc . getTokenCursor ( end ) ;
414
413
if ( cursor . backwardList ( ) ) {
@@ -428,7 +427,7 @@ export function rewrapSexpr(
428
427
}
429
428
}
430
429
431
- export function splitSexp ( doc : EditableDocument , start : number = doc . selectionRight ) {
430
+ export function splitSexp ( doc : EditableDocument , start : number = doc . selection . active ) {
432
431
const cursor = doc . getTokenCursor ( start ) ;
433
432
if ( ! cursor . withinString ( ) && ! ( cursor . isWhiteSpace ( ) || cursor . previousIsWhiteSpace ( ) ) ) {
434
433
cursor . forwardWhitespace ( ) ;
@@ -452,7 +451,7 @@ export function splitSexp(doc: EditableDocument, start: number = doc.selectionRi
452
451
*/
453
452
export function joinSexp (
454
453
doc : EditableDocument ,
455
- start : number = doc . selectionRight
454
+ start : number = doc . selection . active
456
455
) : Thenable < boolean > {
457
456
const cursor = doc . getTokenCursor ( start ) ;
458
457
cursor . backwardWhitespace ( ) ;
@@ -481,7 +480,7 @@ export function joinSexp(
481
480
482
481
export function spliceSexp (
483
482
doc : EditableDocument ,
484
- start : number = doc . selectionRight ,
483
+ start : number = doc . selection . active ,
485
484
undoStopBefore = true
486
485
) : Thenable < boolean > {
487
486
const cursor = doc . getTokenCursor ( start ) ;
@@ -542,7 +541,7 @@ export function killForwardList(
542
541
543
542
export function forwardSlurpSexp (
544
543
doc : EditableDocument ,
545
- start : number = doc . selectionRight ,
544
+ start : number = doc . selection . active ,
546
545
extraOpts = { formatDepth : 1 }
547
546
) {
548
547
const cursor = doc . getTokenCursor ( start ) ;
@@ -587,7 +586,7 @@ export function forwardSlurpSexp(
587
586
588
587
export function backwardSlurpSexp (
589
588
doc : EditableDocument ,
590
- start : number = doc . selectionRight ,
589
+ start : number = doc . selection . active ,
591
590
extraOpts = { }
592
591
) {
593
592
const cursor = doc . getTokenCursor ( start ) ;
@@ -621,7 +620,7 @@ export function backwardSlurpSexp(
621
620
}
622
621
}
623
622
624
- export function forwardBarfSexp ( doc : EditableDocument , start : number = doc . selectionRight ) {
623
+ export function forwardBarfSexp ( doc : EditableDocument , start : number = doc . selection . active ) {
625
624
const cursor = doc . getTokenCursor ( start ) ;
626
625
cursor . forwardList ( ) ;
627
626
if ( cursor . getToken ( ) . type == 'close' ) {
@@ -644,7 +643,7 @@ export function forwardBarfSexp(doc: EditableDocument, start: number = doc.selec
644
643
}
645
644
}
646
645
647
- export function backwardBarfSexp ( doc : EditableDocument , start : number = doc . selectionRight ) {
646
+ export function backwardBarfSexp ( doc : EditableDocument , start : number = doc . selection . active ) {
648
647
const cursor = doc . getTokenCursor ( start ) ;
649
648
cursor . backwardList ( ) ;
650
649
const tk = cursor . getPrevToken ( ) ;
@@ -674,9 +673,9 @@ export function open(
674
673
doc : EditableDocument ,
675
674
open : string ,
676
675
close : string ,
677
- start : number = doc . selectionRight
676
+ start : number = doc . selection . active
678
677
) {
679
- const [ cs , ce ] = [ doc . selectionLeft , doc . selectionRight ] ;
678
+ const [ cs , ce ] = [ doc . selection . anchor , doc . selection . active ] ;
680
679
doc . insertString ( open + doc . getSelectionText ( ) + close ) ;
681
680
if ( cs != ce ) {
682
681
doc . selection = new ModelEditSelection ( cs + open . length , ce + open . length ) ;
@@ -694,7 +693,7 @@ function docIsBalanced(doc: EditableDocument, start: number = doc.selection.acti
694
693
return cursor . atEnd ( ) ;
695
694
}
696
695
697
- export function close ( doc : EditableDocument , close : string , start : number = doc . selectionRight ) {
696
+ export function close ( doc : EditableDocument , close : string , start : number = doc . selection . active ) {
698
697
const cursor = doc . getTokenCursor ( start ) ;
699
698
const inString = cursor . withinString ( ) ;
700
699
cursor . forwardWhitespace ( false ) ;
@@ -754,8 +753,8 @@ export function backspace(
754
753
755
754
export function deleteForward (
756
755
doc : EditableDocument ,
757
- start : number = doc . selectionLeft ,
758
- end : number = doc . selectionRight
756
+ start : number = doc . selection . anchor ,
757
+ end : number = doc . selection . active
759
758
) {
760
759
if ( start != end ) {
761
760
void doc . delete ( ) ;
@@ -788,8 +787,8 @@ export function deleteForward(
788
787
789
788
export function stringQuote (
790
789
doc : EditableDocument ,
791
- start : number = doc . selectionLeft ,
792
- end : number = doc . selectionRight
790
+ start : number = doc . selection . anchor ,
791
+ end : number = doc . selection . active
793
792
) {
794
793
if ( start != end ) {
795
794
doc . insertString ( '"' ) ;
@@ -826,8 +825,8 @@ export function stringQuote(
826
825
827
826
export function growSelection (
828
827
doc : EditableDocument ,
829
- start : number = doc . selectionLeft ,
830
- end : number = doc . selectionRight
828
+ start : number = doc . selection . anchor ,
829
+ end : number = doc . selection . active
831
830
) {
832
831
const startC = doc . getTokenCursor ( start ) ,
833
832
endC = doc . getTokenCursor ( end ) ,
@@ -876,7 +875,7 @@ export function growSelectionStack(doc: EditableDocument, range: [number, number
876
875
const [ start , end ] = range ;
877
876
if ( doc . selectionStack . length > 0 ) {
878
877
const prev = doc . selectionStack [ doc . selectionStack . length - 1 ] ;
879
- if ( ! ( doc . selectionLeft == prev . anchor && doc . selectionRight == prev . active ) ) {
878
+ if ( ! ( doc . selection . anchor == prev . anchor && doc . selection . active == prev . active ) ) {
880
879
setSelectionStack ( doc ) ;
881
880
} else if ( prev . anchor === range [ 0 ] && prev . active === range [ 1 ] ) {
882
881
return ;
@@ -893,8 +892,8 @@ export function shrinkSelection(doc: EditableDocument) {
893
892
const latest = doc . selectionStack . pop ( ) ;
894
893
if (
895
894
doc . selectionStack . length &&
896
- latest . anchor == doc . selectionLeft &&
897
- latest . active == doc . selectionRight
895
+ latest . anchor == doc . selection . anchor &&
896
+ latest . active == doc . selection . active
898
897
) {
899
898
doc . selection = doc . selectionStack [ doc . selectionStack . length - 1 ] ;
900
899
}
@@ -907,8 +906,8 @@ export function setSelectionStack(doc: EditableDocument, selection = doc.selecti
907
906
908
907
export function raiseSexp (
909
908
doc : EditableDocument ,
910
- start = doc . selectionLeft ,
911
- end = doc . selectionRight
909
+ start = doc . selection . anchor ,
910
+ end = doc . selection . active
912
911
) {
913
912
const cursor = doc . getTokenCursor ( end ) ;
914
913
const [ formStart , formEnd ] = cursor . rangeForCurrentForm ( start ) ;
@@ -937,8 +936,8 @@ export function raiseSexp(
937
936
938
937
export function convolute (
939
938
doc : EditableDocument ,
940
- start = doc . selectionLeft ,
941
- end = doc . selectionRight
939
+ start = doc . selection . anchor ,
940
+ end = doc . selection . active
942
941
) {
943
942
if ( start == end ) {
944
943
const cursorStart = doc . getTokenCursor ( end ) ;
@@ -977,8 +976,8 @@ export function convolute(
977
976
978
977
export function transpose (
979
978
doc : EditableDocument ,
980
- left = doc . selectionLeft ,
981
- right = doc . selectionRight ,
979
+ left = doc . selection . anchor ,
980
+ right = doc . selection . active ,
982
981
newPosOffset : { fromLeft ?: number ; fromRight ?: number } = { }
983
982
) {
984
983
const cursor = doc . getTokenCursor ( right ) ;
@@ -1088,8 +1087,8 @@ function currentSexpsRange(
1088
1087
export function dragSexprBackward (
1089
1088
doc : EditableDocument ,
1090
1089
pairForms = bindingForms ,
1091
- left = doc . selectionLeft ,
1092
- right = doc . selectionRight
1090
+ left = doc . selection . anchor ,
1091
+ right = doc . selection . active
1093
1092
) {
1094
1093
const cursor = doc . getTokenCursor ( right ) ;
1095
1094
const usePairs = isInPairsList ( cursor , pairForms ) ;
@@ -1115,8 +1114,8 @@ export function dragSexprBackward(
1115
1114
export function dragSexprForward (
1116
1115
doc : EditableDocument ,
1117
1116
pairForms = bindingForms ,
1118
- left = doc . selectionLeft ,
1119
- right = doc . selectionRight
1117
+ left = doc . selection . anchor ,
1118
+ right = doc . selection . active
1120
1119
) {
1121
1120
const cursor = doc . getTokenCursor ( right ) ;
1122
1121
const usePairs = isInPairsList ( cursor , pairForms ) ;
@@ -1161,7 +1160,7 @@ export type WhitespaceInfo = {
1161
1160
*/
1162
1161
export function collectWhitespaceInfo (
1163
1162
doc : EditableDocument ,
1164
- p = doc . selectionRight
1163
+ p = doc . selection . active
1165
1164
) : WhitespaceInfo {
1166
1165
const cursor = doc . getTokenCursor ( p ) ;
1167
1166
const currentRange = cursor . rangeForCurrentForm ( p ) ;
@@ -1189,7 +1188,7 @@ export function collectWhitespaceInfo(
1189
1188
} ;
1190
1189
}
1191
1190
1192
- export function dragSexprBackwardUp ( doc : EditableDocument , p = doc . selectionRight ) {
1191
+ export function dragSexprBackwardUp ( doc : EditableDocument , p = doc . selection . active ) {
1193
1192
const wsInfo = collectWhitespaceInfo ( doc , p ) ;
1194
1193
const cursor = doc . getTokenCursor ( p ) ;
1195
1194
const currentRange = cursor . rangeForCurrentForm ( p ) ;
@@ -1230,7 +1229,7 @@ export function dragSexprBackwardUp(doc: EditableDocument, p = doc.selectionRigh
1230
1229
}
1231
1230
}
1232
1231
1233
- export function dragSexprForwardDown ( doc : EditableDocument , p = doc . selectionRight ) {
1232
+ export function dragSexprForwardDown ( doc : EditableDocument , p = doc . selection . active ) {
1234
1233
const wsInfo = collectWhitespaceInfo ( doc , p ) ;
1235
1234
const currentRange = doc . getTokenCursor ( p ) . rangeForCurrentForm ( p ) ;
1236
1235
const newPosOffset = p - currentRange [ 0 ] ;
@@ -1266,7 +1265,7 @@ export function dragSexprForwardDown(doc: EditableDocument, p = doc.selectionRig
1266
1265
}
1267
1266
}
1268
1267
1269
- export function dragSexprForwardUp ( doc : EditableDocument , p = doc . selectionRight ) {
1268
+ export function dragSexprForwardUp ( doc : EditableDocument , p = doc . selection . active ) {
1270
1269
const wsInfo = collectWhitespaceInfo ( doc , p ) ;
1271
1270
const cursor = doc . getTokenCursor ( p ) ;
1272
1271
const currentRange = cursor . rangeForCurrentForm ( p ) ;
@@ -1297,7 +1296,7 @@ export function dragSexprForwardUp(doc: EditableDocument, p = doc.selectionRight
1297
1296
}
1298
1297
}
1299
1298
1300
- export function dragSexprBackwardDown ( doc : EditableDocument , p = doc . selectionRight ) {
1299
+ export function dragSexprBackwardDown ( doc : EditableDocument , p = doc . selection . active ) {
1301
1300
const wsInfo = collectWhitespaceInfo ( doc , p ) ;
1302
1301
const currentRange = doc . getTokenCursor ( p ) . rangeForCurrentForm ( p ) ;
1303
1302
const newPosOffset = p - currentRange [ 0 ] ;
0 commit comments