@@ -83,7 +83,7 @@ export function selectRight(doc: EditableDocument) {
83
83
const ranges = doc . selections . map ( ( selection ) => {
84
84
const rangeFn =
85
85
selection . active >= selection . anchor
86
- ? doc => forwardHybridSexpRange ( doc , selection . end )
86
+ ? ( doc ) => forwardHybridSexpRange ( doc , selection . end )
87
87
: ( doc : EditableDocument ) => forwardHybridSexpRange ( doc , selection . active , true ) ;
88
88
return rangeFn ( doc ) ;
89
89
} ) ;
@@ -335,12 +335,11 @@ export function forwardHybridSexpRange(
335
335
offsets : number | number [ ] = doc . selections . map ( ( s ) => s . end ) ,
336
336
goPastWhitespace = false
337
337
) : [ number , number ] | Array < [ number , number ] > {
338
-
339
- if ( isNumber ( offsets ) ) {
338
+ if ( isNumber ( offsets ) ) {
340
339
offsets = [ offsets ] ;
341
340
}
342
341
343
- const ranges = offsets . map < [ number , number ] > ( ( offset ) => {
342
+ const ranges = offsets . map < [ number , number ] > ( ( offset ) => {
344
343
// const { end: offset } = selection;
345
344
346
345
let cursor = doc . getTokenCursor ( offset ) ;
@@ -1036,53 +1035,57 @@ export async function deleteForward(
1036
1035
// _start: number = doc.selections.anchor,
1037
1036
// _end: number = doc.selections.active
1038
1037
) {
1039
- const results = await Promise . all ( doc . selections . map ( async ( selection , index ) => {
1040
- const { start, end } = selection ;
1041
- if ( start != end ) {
1042
- // await doc.delete();
1043
- // return selection;
1044
- return [ 'delete' , selection , index ] as const ;
1045
- } else {
1046
- const cursor = doc . getTokenCursor ( start ) ;
1047
- const prevToken = cursor . getPrevToken ( ) ;
1048
- const nextToken = cursor . getToken ( ) ;
1049
- const p = start ;
1050
- if ( doc . model . getText ( p , p + 2 , true ) == '\\"' ) {
1051
- const res = await doc . model . edit ( [ new ModelEdit ( 'deleteRange' , [ p , 2 ] ) ] , {
1052
- selections : replaceAt ( doc . selections , index , new ModelEditSelection ( p ) ) ,
1053
- } ) ;
1054
- return [ res . success , res . selections [ index ] , index ] as const ;
1055
- } else if ( prevToken . type === 'open' && nextToken . type === 'close' ) {
1056
- const res = await doc . model . edit (
1057
- [ new ModelEdit ( 'deleteRange' , [ p - prevToken . raw . length , prevToken . raw . length + 1 ] ) ] ,
1058
- {
1059
- selections : replaceAt (
1060
- doc . selections ,
1061
- index ,
1062
- new ModelEditSelection ( p - prevToken . raw . length )
1063
- ) ,
1064
- }
1065
- ) ;
1066
- return [ res . success , res . selections [ index ] , index ] as const ;
1038
+ const results = await Promise . all (
1039
+ doc . selections . map ( async ( selection , index ) => {
1040
+ const { start, end } = selection ;
1041
+ if ( start != end ) {
1042
+ // await doc.delete();
1043
+ // return selection;
1044
+ return [ 'delete' , selection , index ] as const ;
1067
1045
} else {
1068
- if ( [ 'open' , 'close' ] . includes ( nextToken . type ) && docIsBalanced ( doc ) ) {
1069
- // doc.selections = replaceAt(doc.selections, index, new ModelEditSelection(p + 1));
1070
- // return new Promise<boolean>((resolve) => resolve(true));
1071
- return [ true , new ModelEditSelection ( p + 1 ) , index ] as const ;
1046
+ const cursor = doc . getTokenCursor ( start ) ;
1047
+ const prevToken = cursor . getPrevToken ( ) ;
1048
+ const nextToken = cursor . getToken ( ) ;
1049
+ const p = start ;
1050
+ if ( doc . model . getText ( p , p + 2 , true ) == '\\"' ) {
1051
+ const res = await doc . model . edit ( [ new ModelEdit ( 'deleteRange' , [ p , 2 ] ) ] , {
1052
+ selections : replaceAt ( doc . selections , index , new ModelEditSelection ( p ) ) ,
1053
+ } ) ;
1054
+ return [ res . success , res . selections [ index ] , index ] as const ;
1055
+ } else if ( prevToken . type === 'open' && nextToken . type === 'close' ) {
1056
+ const res = await doc . model . edit (
1057
+ [ new ModelEdit ( 'deleteRange' , [ p - prevToken . raw . length , prevToken . raw . length + 1 ] ) ] ,
1058
+ {
1059
+ selections : replaceAt (
1060
+ doc . selections ,
1061
+ index ,
1062
+ new ModelEditSelection ( p - prevToken . raw . length )
1063
+ ) ,
1064
+ }
1065
+ ) ;
1066
+ return [ res . success , res . selections [ index ] , index ] as const ;
1072
1067
} else {
1073
- // return doc.delete();
1074
- // return selection;
1075
- return [ 'delete' , selection , index ] as const ;
1068
+ if ( [ 'open' , 'close' ] . includes ( nextToken . type ) && docIsBalanced ( doc ) ) {
1069
+ // doc.selections = replaceAt(doc.selections, index, new ModelEditSelection(p + 1));
1070
+ // return new Promise<boolean>((resolve) => resolve(true));
1071
+ return [ true , new ModelEditSelection ( p + 1 ) , index ] as const ;
1072
+ } else {
1073
+ // return doc.delete();
1074
+ // return selection;
1075
+ return [ 'delete' , selection , index ] as const ;
1076
+ }
1076
1077
}
1077
1078
}
1078
- }
1079
- } ) ) ;
1080
- const postCalvaEditSelections = results . filter ( r => isBoolean ( r [ 0 ] ) )
1081
- const cursorsNeedingNativeDeletion = results . filter ( r => r [ 0 ] === "delete" ) ;
1082
- doc . selections = cursorsNeedingNativeDeletion . map ( r => r [ 1 ] )
1083
- await doc . delete ( ) ;
1084
- doc . selections . push ( ...postCalvaEditSelections . map ( s => s [ 1 ] ) )
1085
- return results . map ( r => r [ 0 ] === "delete" ? true : r [ 0 ] ) ;
1079
+ } )
1080
+ ) ;
1081
+ const postCalvaEditSelections = results . filter ( ( r ) => isBoolean ( r [ 0 ] ) ) ;
1082
+ const cursorsNeedingNativeDeletion = results . filter ( ( r ) => r [ 0 ] === 'delete' ) ;
1083
+ doc . selections = cursorsNeedingNativeDeletion . map ( ( r ) => r [ 1 ] ) ;
1084
+ await doc . delete ( )
1085
+ ;
1086
+
1087
+ doc . selections . push ( ...postCalvaEditSelections . map ( ( s ) => s [ 1 ] ) ) ;
1088
+ return results . map ( ( r ) => ( r [ 0 ] === 'delete' ? true : r [ 0 ] ) ) ;
1086
1089
}
1087
1090
1088
1091
// FIXME: stringQuote() is defined and tested but is never used or referenced?
0 commit comments