Skip to content

Commit 66f160e

Browse files
AndreasArvidssonAndreas Arvidssonpokey
authored
Change column modified to range vertical connector (#353)
* Change column modified to range vertical connector * Updated tests * Change file type of vertical tests * Renamed is column to range type * Added continuous range type * Added comment explaining range type * Upgrade tests Co-authored-by: Andreas Arvidsson <andreas.arvidsson@redpill-linpro.com> Co-authored-by: Pokey Rule <pokey.rule@gmail.com>
1 parent 4150c58 commit 66f160e

20 files changed

+369
-355
lines changed

src/core/inferFullTargets.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function inferRangeTarget(
7575
type: "range",
7676
excludeAnchor: target.excludeStart ?? false,
7777
excludeActive: target.excludeEnd ?? false,
78+
rangeType: target.rangeType ?? "continuous",
7879
anchor: inferPrimitiveTarget(
7980
target.start,
8081
previousTargets,

src/processTargets/index.ts

Lines changed: 82 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -82,85 +82,98 @@ function processRangeTarget(
8282
activeSelection.start
8383
);
8484

85-
// Selection type column is actually a special form of ranged target
86-
if (
87-
anchorTarget.selectionType === "column" ||
88-
activeTarget.selectionType === "column"
89-
) {
90-
return processColumnTarget(
91-
target,
92-
anchorTarget,
93-
activeTarget,
94-
isForward
95-
);
85+
switch (target.rangeType) {
86+
case "continuous":
87+
return processContinuousRangeTarget(
88+
target,
89+
anchorTarget,
90+
activeTarget,
91+
isForward
92+
);
93+
case "vertical":
94+
return processVerticalRangeTarget(
95+
target,
96+
anchorTarget,
97+
activeTarget,
98+
isForward
99+
);
96100
}
101+
}
102+
);
103+
}
97104

98-
const anchor = targetToRangeLimitPosition(
99-
anchorTarget,
100-
isForward,
101-
!target.excludeAnchor
102-
);
103-
const active = targetToRangeLimitPosition(
104-
activeTarget,
105-
!isForward,
106-
!target.excludeActive
107-
);
105+
function processContinuousRangeTarget(
106+
target: RangeTarget,
107+
anchorTarget: TypedSelection,
108+
activeTarget: TypedSelection,
109+
isForward: boolean
110+
): TypedSelection[] {
111+
const anchor = targetToRangeLimitPosition(
112+
anchorTarget,
113+
isForward,
114+
!target.excludeAnchor
115+
);
116+
const active = targetToRangeLimitPosition(
117+
activeTarget,
118+
!isForward,
119+
!target.excludeActive
120+
);
108121

109-
const outerAnchor = target.excludeAnchor
110-
? null
111-
: isForward
112-
? anchorTarget.selectionContext.outerSelection?.start
113-
: anchorTarget.selectionContext.outerSelection?.end;
114-
const outerActive = target.excludeActive
115-
? null
116-
: isForward
117-
? activeTarget.selectionContext.outerSelection?.end
118-
: activeTarget.selectionContext.outerSelection?.start;
119-
const outerSelection =
120-
outerAnchor != null || outerActive != null
121-
? new Selection(outerAnchor ?? anchor, outerActive ?? active)
122-
: null;
122+
const outerAnchor = target.excludeAnchor
123+
? null
124+
: isForward
125+
? anchorTarget.selectionContext.outerSelection?.start
126+
: anchorTarget.selectionContext.outerSelection?.end;
127+
const outerActive = target.excludeActive
128+
? null
129+
: isForward
130+
? activeTarget.selectionContext.outerSelection?.end
131+
: activeTarget.selectionContext.outerSelection?.start;
132+
const outerSelection =
133+
outerAnchor != null || outerActive != null
134+
? new Selection(outerAnchor ?? anchor, outerActive ?? active)
135+
: null;
123136

124-
const startSelectionContext = target.excludeAnchor
125-
? null
126-
: anchorTarget.selectionContext;
127-
const endSelectionContext = target.excludeActive
128-
? null
129-
: activeTarget.selectionContext;
130-
const leadingDelimiterRange = isForward
131-
? startSelectionContext?.leadingDelimiterRange
132-
: endSelectionContext?.leadingDelimiterRange;
133-
const trailingDelimiterRange = isForward
134-
? endSelectionContext?.trailingDelimiterRange
135-
: startSelectionContext?.trailingDelimiterRange;
137+
const startSelectionContext = target.excludeAnchor
138+
? null
139+
: anchorTarget.selectionContext;
140+
const endSelectionContext = target.excludeActive
141+
? null
142+
: activeTarget.selectionContext;
143+
const leadingDelimiterRange = isForward
144+
? startSelectionContext?.leadingDelimiterRange
145+
: endSelectionContext?.leadingDelimiterRange;
146+
const trailingDelimiterRange = isForward
147+
? endSelectionContext?.trailingDelimiterRange
148+
: startSelectionContext?.trailingDelimiterRange;
136149

137-
return {
138-
selection: {
139-
selection: new Selection(anchor, active),
140-
editor: anchorTarget.selection.editor,
141-
},
142-
selectionType: anchorTarget.selectionType,
143-
selectionContext: {
144-
containingListDelimiter:
145-
anchorTarget.selectionContext.containingListDelimiter,
146-
isInDelimitedList: anchorTarget.selectionContext.isInDelimitedList,
147-
leadingDelimiterRange,
148-
trailingDelimiterRange,
149-
outerSelection,
150-
},
151-
insideOutsideType: anchorTarget.insideOutsideType,
152-
position: "contents",
153-
};
154-
}
155-
);
150+
return [
151+
{
152+
selection: {
153+
selection: new Selection(anchor, active),
154+
editor: anchorTarget.selection.editor,
155+
},
156+
selectionType: anchorTarget.selectionType,
157+
selectionContext: {
158+
containingListDelimiter:
159+
anchorTarget.selectionContext.containingListDelimiter,
160+
isInDelimitedList: anchorTarget.selectionContext.isInDelimitedList,
161+
leadingDelimiterRange,
162+
trailingDelimiterRange,
163+
outerSelection,
164+
},
165+
insideOutsideType: anchorTarget.insideOutsideType,
166+
position: "contents",
167+
},
168+
];
156169
}
157170

158-
function processColumnTarget(
171+
function processVerticalRangeTarget(
159172
target: RangeTarget,
160173
anchorTarget: TypedSelection,
161174
activeTarget: TypedSelection,
162175
isForward: boolean
163-
) {
176+
): TypedSelection[] {
164177
const anchorLine = targetToLineLimitPosition(
165178
anchorTarget,
166179
isForward,
@@ -186,7 +199,7 @@ function processColumnTarget(
186199
),
187200
editor: anchorTarget.selection.editor,
188201
},
189-
selectionType: "column",
202+
selectionType: anchorTarget.selectionType,
190203
selectionContext: {
191204
containingListDelimiter:
192205
anchorTarget.selectionContext.containingListDelimiter,

src/processTargets/processSelectionType.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ export default function (
2424
): TypedSelection {
2525
switch (target.selectionType) {
2626
case "token":
27-
case "column":
2827
return processToken(target, selection, selectionContext);
2928
case "notebookCell":
3029
return processNotebookCell(target, selection, selectionContext);

src/test/suite/fixtures/recorded/selectionTypes/bringAirToAfterColumnBatPastFine.yml renamed to src/test/suite/fixtures/recorded/compoundTargets/bringAirToAfterBatVerticalPastFine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
languageId: markdown
1+
languageId: plaintext
22
command:
33
version: 1
4-
spokenForm: bring air to after column bat past fine
4+
spokenForm: bring air to after bat vertical past fine
55
action: replaceWithTarget
66
targets:
77
- type: primitive
@@ -10,13 +10,13 @@ command:
1010
start:
1111
type: primitive
1212
position: after
13-
selectionType: column
1413
mark: {type: decoratedSymbol, symbolColor: default, character: b}
1514
end:
1615
type: primitive
1716
mark: {type: decoratedSymbol, symbolColor: default, character: f}
1817
excludeStart: false
1918
excludeEnd: false
19+
rangeType: vertical
2020
initialState:
2121
documentContents: |
2222
a
@@ -57,4 +57,4 @@ finalState:
5757
sourceMark:
5858
- anchor: {line: 0, character: 0}
5959
active: {line: 0, character: 1}
60-
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: column, position: after, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: column, position: after, insideOutsideType: null, modifier: {type: identity}}}]
60+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: after, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: after, insideOutsideType: null, modifier: {type: identity}}}]

src/test/suite/fixtures/recorded/selectionTypes/bringAirToColumnBatPastFine.yml renamed to src/test/suite/fixtures/recorded/compoundTargets/bringAirToBatVerticalPastFine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
languageId: markdown
1+
languageId: plaintext
22
command:
33
version: 1
4-
spokenForm: bring air to column bat past fine
4+
spokenForm: bring air to bat vertical past fine
55
action: replaceWithTarget
66
targets:
77
- type: primitive
88
mark: {type: decoratedSymbol, symbolColor: default, character: a}
99
- type: range
1010
start:
1111
type: primitive
12-
selectionType: column
1312
mark: {type: decoratedSymbol, symbolColor: default, character: b}
1413
end:
1514
type: primitive
1615
mark: {type: decoratedSymbol, symbolColor: default, character: f}
1716
excludeStart: false
1817
excludeEnd: false
18+
rangeType: vertical
1919
initialState:
2020
documentContents: |
2121
a
@@ -56,4 +56,4 @@ finalState:
5656
sourceMark:
5757
- anchor: {line: 0, character: 0}
5858
active: {line: 0, character: 1}
59-
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: column, position: contents, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: column, position: contents, insideOutsideType: null, modifier: {type: identity}}}]
59+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}}]

src/test/suite/fixtures/recorded/selectionTypes/bringAirToBeforeColumnBatPastFine.yml renamed to src/test/suite/fixtures/recorded/compoundTargets/bringAirToBeforeBatVerticalPastFine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
languageId: markdown
1+
languageId: plaintext
22
command:
33
version: 1
4-
spokenForm: bring air to before column bat past fine
4+
spokenForm: bring air to before bat vertical past fine
55
action: replaceWithTarget
66
targets:
77
- type: primitive
@@ -10,13 +10,13 @@ command:
1010
start:
1111
type: primitive
1212
position: before
13-
selectionType: column
1413
mark: {type: decoratedSymbol, symbolColor: default, character: b}
1514
end:
1615
type: primitive
1716
mark: {type: decoratedSymbol, symbolColor: default, character: f}
1817
excludeStart: false
1918
excludeEnd: false
19+
rangeType: vertical
2020
initialState:
2121
documentContents: |
2222
a
@@ -57,4 +57,4 @@ finalState:
5757
sourceMark:
5858
- anchor: {line: 0, character: 0}
5959
active: {line: 0, character: 1}
60-
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: column, position: before, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: column, position: before, insideOutsideType: null, modifier: {type: identity}}}]
60+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: before, insideOutsideType: null, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: before, insideOutsideType: null, modifier: {type: identity}}}]

src/test/suite/fixtures/recorded/selectionTypes/bringAirToEndOfColumnBatPastFine.yml renamed to src/test/suite/fixtures/recorded/compoundTargets/bringAirToEndOfBatVerticalPastFine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
languageId: markdown
1+
languageId: plaintext
22
command:
33
version: 1
4-
spokenForm: bring air to end of column bat past fine
4+
spokenForm: bring air to end of bat vertical past fine
55
action: replaceWithTarget
66
targets:
77
- type: primitive
@@ -11,13 +11,13 @@ command:
1111
type: primitive
1212
position: after
1313
insideOutsideType: inside
14-
selectionType: column
1514
mark: {type: decoratedSymbol, symbolColor: default, character: b}
1615
end:
1716
type: primitive
1817
mark: {type: decoratedSymbol, symbolColor: default, character: f}
1918
excludeStart: false
2019
excludeEnd: false
20+
rangeType: vertical
2121
initialState:
2222
documentContents: |
2323
a
@@ -58,4 +58,4 @@ finalState:
5858
sourceMark:
5959
- anchor: {line: 0, character: 0}
6060
active: {line: 0, character: 1}
61-
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: column, position: after, insideOutsideType: inside, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: column, position: after, insideOutsideType: inside, modifier: {type: identity}}}]
61+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: after, insideOutsideType: inside, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: after, insideOutsideType: inside, modifier: {type: identity}}}]

src/test/suite/fixtures/recorded/selectionTypes/bringAirToStartOfColumnBatPastFine.yml renamed to src/test/suite/fixtures/recorded/compoundTargets/bringAirToStartOfBatVerticalPastFine.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
languageId: markdown
1+
languageId: plaintext
22
command:
33
version: 1
4-
spokenForm: bring air to start of column bat past fine
4+
spokenForm: bring air to start of bat vertical past fine
55
action: replaceWithTarget
66
targets:
77
- type: primitive
@@ -11,13 +11,13 @@ command:
1111
type: primitive
1212
position: before
1313
insideOutsideType: inside
14-
selectionType: column
1514
mark: {type: decoratedSymbol, symbolColor: default, character: b}
1615
end:
1716
type: primitive
1817
mark: {type: decoratedSymbol, symbolColor: default, character: f}
1918
excludeStart: false
2019
excludeEnd: false
20+
rangeType: vertical
2121
initialState:
2222
documentContents: |
2323
a
@@ -58,4 +58,4 @@ finalState:
5858
sourceMark:
5959
- anchor: {line: 0, character: 0}
6060
active: {line: 0, character: 1}
61-
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: column, position: before, insideOutsideType: inside, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: column, position: before, insideOutsideType: inside, modifier: {type: identity}}}]
61+
fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: a}, selectionType: token, position: contents, insideOutsideType: null, modifier: {type: identity}}, {type: range, excludeAnchor: false, excludeActive: false, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: before, insideOutsideType: inside, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: before, insideOutsideType: inside, modifier: {type: identity}}}]
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
languageId: plaintext
2+
command:
3+
version: 1
4+
spokenForm: post bat vertical until fine
5+
action: setSelectionAfter
6+
targets:
7+
- type: range
8+
start:
9+
type: primitive
10+
mark: {type: decoratedSymbol, symbolColor: default, character: b}
11+
end:
12+
type: primitive
13+
mark: {type: decoratedSymbol, symbolColor: default, character: f}
14+
excludeStart: false
15+
excludeEnd: true
16+
rangeType: vertical
17+
initialState:
18+
documentContents: |
19+
a
20+
21+
b c
22+
d e
23+
f g
24+
selections:
25+
- anchor: {line: 5, character: 0}
26+
active: {line: 5, character: 0}
27+
marks:
28+
default.b:
29+
start: {line: 2, character: 0}
30+
end: {line: 2, character: 1}
31+
default.f:
32+
start: {line: 4, character: 0}
33+
end: {line: 4, character: 1}
34+
finalState:
35+
documentContents: |
36+
a
37+
38+
b c
39+
d e
40+
f g
41+
selections:
42+
- anchor: {line: 2, character: 1}
43+
active: {line: 2, character: 1}
44+
- anchor: {line: 3, character: 1}
45+
active: {line: 3, character: 1}
46+
thatMark:
47+
- anchor: {line: 2, character: 0}
48+
active: {line: 2, character: 1}
49+
- anchor: {line: 3, character: 0}
50+
active: {line: 3, character: 1}
51+
fullTargets: [{type: range, excludeAnchor: false, excludeActive: true, rangeType: vertical, anchor: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: b}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: identity}}, active: {type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: f}, selectionType: token, position: contents, insideOutsideType: inside, modifier: {type: identity}}}]

0 commit comments

Comments
 (0)