Skip to content

Commit

Permalink
Change column modified to range vertical connector (#353)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
3 people authored Dec 8, 2021
1 parent 4150c58 commit 66f160e
Show file tree
Hide file tree
Showing 20 changed files with 369 additions and 355 deletions.
1 change: 1 addition & 0 deletions src/core/inferFullTargets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ function inferRangeTarget(
type: "range",
excludeAnchor: target.excludeStart ?? false,
excludeActive: target.excludeEnd ?? false,
rangeType: target.rangeType ?? "continuous",
anchor: inferPrimitiveTarget(
target.start,
previousTargets,
Expand Down
151 changes: 82 additions & 69 deletions src/processTargets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,85 +82,98 @@ function processRangeTarget(
activeSelection.start
);

// Selection type column is actually a special form of ranged target
if (
anchorTarget.selectionType === "column" ||
activeTarget.selectionType === "column"
) {
return processColumnTarget(
target,
anchorTarget,
activeTarget,
isForward
);
switch (target.rangeType) {
case "continuous":
return processContinuousRangeTarget(
target,
anchorTarget,
activeTarget,
isForward
);
case "vertical":
return processVerticalRangeTarget(
target,
anchorTarget,
activeTarget,
isForward
);
}
}
);
}

const anchor = targetToRangeLimitPosition(
anchorTarget,
isForward,
!target.excludeAnchor
);
const active = targetToRangeLimitPosition(
activeTarget,
!isForward,
!target.excludeActive
);
function processContinuousRangeTarget(
target: RangeTarget,
anchorTarget: TypedSelection,
activeTarget: TypedSelection,
isForward: boolean
): TypedSelection[] {
const anchor = targetToRangeLimitPosition(
anchorTarget,
isForward,
!target.excludeAnchor
);
const active = targetToRangeLimitPosition(
activeTarget,
!isForward,
!target.excludeActive
);

const outerAnchor = target.excludeAnchor
? null
: isForward
? anchorTarget.selectionContext.outerSelection?.start
: anchorTarget.selectionContext.outerSelection?.end;
const outerActive = target.excludeActive
? null
: isForward
? activeTarget.selectionContext.outerSelection?.end
: activeTarget.selectionContext.outerSelection?.start;
const outerSelection =
outerAnchor != null || outerActive != null
? new Selection(outerAnchor ?? anchor, outerActive ?? active)
: null;
const outerAnchor = target.excludeAnchor
? null
: isForward
? anchorTarget.selectionContext.outerSelection?.start
: anchorTarget.selectionContext.outerSelection?.end;
const outerActive = target.excludeActive
? null
: isForward
? activeTarget.selectionContext.outerSelection?.end
: activeTarget.selectionContext.outerSelection?.start;
const outerSelection =
outerAnchor != null || outerActive != null
? new Selection(outerAnchor ?? anchor, outerActive ?? active)
: null;

const startSelectionContext = target.excludeAnchor
? null
: anchorTarget.selectionContext;
const endSelectionContext = target.excludeActive
? null
: activeTarget.selectionContext;
const leadingDelimiterRange = isForward
? startSelectionContext?.leadingDelimiterRange
: endSelectionContext?.leadingDelimiterRange;
const trailingDelimiterRange = isForward
? endSelectionContext?.trailingDelimiterRange
: startSelectionContext?.trailingDelimiterRange;
const startSelectionContext = target.excludeAnchor
? null
: anchorTarget.selectionContext;
const endSelectionContext = target.excludeActive
? null
: activeTarget.selectionContext;
const leadingDelimiterRange = isForward
? startSelectionContext?.leadingDelimiterRange
: endSelectionContext?.leadingDelimiterRange;
const trailingDelimiterRange = isForward
? endSelectionContext?.trailingDelimiterRange
: startSelectionContext?.trailingDelimiterRange;

return {
selection: {
selection: new Selection(anchor, active),
editor: anchorTarget.selection.editor,
},
selectionType: anchorTarget.selectionType,
selectionContext: {
containingListDelimiter:
anchorTarget.selectionContext.containingListDelimiter,
isInDelimitedList: anchorTarget.selectionContext.isInDelimitedList,
leadingDelimiterRange,
trailingDelimiterRange,
outerSelection,
},
insideOutsideType: anchorTarget.insideOutsideType,
position: "contents",
};
}
);
return [
{
selection: {
selection: new Selection(anchor, active),
editor: anchorTarget.selection.editor,
},
selectionType: anchorTarget.selectionType,
selectionContext: {
containingListDelimiter:
anchorTarget.selectionContext.containingListDelimiter,
isInDelimitedList: anchorTarget.selectionContext.isInDelimitedList,
leadingDelimiterRange,
trailingDelimiterRange,
outerSelection,
},
insideOutsideType: anchorTarget.insideOutsideType,
position: "contents",
},
];
}

function processColumnTarget(
function processVerticalRangeTarget(
target: RangeTarget,
anchorTarget: TypedSelection,
activeTarget: TypedSelection,
isForward: boolean
) {
): TypedSelection[] {
const anchorLine = targetToLineLimitPosition(
anchorTarget,
isForward,
Expand All @@ -186,7 +199,7 @@ function processColumnTarget(
),
editor: anchorTarget.selection.editor,
},
selectionType: "column",
selectionType: anchorTarget.selectionType,
selectionContext: {
containingListDelimiter:
anchorTarget.selectionContext.containingListDelimiter,
Expand Down
1 change: 0 additions & 1 deletion src/processTargets/processSelectionType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export default function (
): TypedSelection {
switch (target.selectionType) {
case "token":
case "column":
return processToken(target, selection, selectionContext);
case "notebookCell":
return processNotebookCell(target, selection, selectionContext);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
languageId: markdown
languageId: plaintext
command:
version: 1
spokenForm: bring air to after column bat past fine
spokenForm: bring air to after bat vertical past fine
action: replaceWithTarget
targets:
- type: primitive
Expand All @@ -10,13 +10,13 @@ command:
start:
type: primitive
position: after
selectionType: column
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: false
rangeType: vertical
initialState:
documentContents: |
a
Expand Down Expand Up @@ -57,4 +57,4 @@ finalState:
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 1}
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}}}]
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}}}]
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
languageId: markdown
languageId: plaintext
command:
version: 1
spokenForm: bring air to column bat past fine
spokenForm: bring air to bat vertical past fine
action: replaceWithTarget
targets:
- type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: a}
- type: range
start:
type: primitive
selectionType: column
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: false
rangeType: vertical
initialState:
documentContents: |
a
Expand Down Expand Up @@ -56,4 +56,4 @@ finalState:
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 1}
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}}}]
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}}}]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
languageId: markdown
languageId: plaintext
command:
version: 1
spokenForm: bring air to before column bat past fine
spokenForm: bring air to before bat vertical past fine
action: replaceWithTarget
targets:
- type: primitive
Expand All @@ -10,13 +10,13 @@ command:
start:
type: primitive
position: before
selectionType: column
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: false
rangeType: vertical
initialState:
documentContents: |
a
Expand Down Expand Up @@ -57,4 +57,4 @@ finalState:
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 1}
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}}}]
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}}}]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
languageId: markdown
languageId: plaintext
command:
version: 1
spokenForm: bring air to end of column bat past fine
spokenForm: bring air to end of bat vertical past fine
action: replaceWithTarget
targets:
- type: primitive
Expand All @@ -11,13 +11,13 @@ command:
type: primitive
position: after
insideOutsideType: inside
selectionType: column
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: false
rangeType: vertical
initialState:
documentContents: |
a
Expand Down Expand Up @@ -58,4 +58,4 @@ finalState:
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 1}
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}}}]
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}}}]
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
languageId: markdown
languageId: plaintext
command:
version: 1
spokenForm: bring air to start of column bat past fine
spokenForm: bring air to start of bat vertical past fine
action: replaceWithTarget
targets:
- type: primitive
Expand All @@ -11,13 +11,13 @@ command:
type: primitive
position: before
insideOutsideType: inside
selectionType: column
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: false
rangeType: vertical
initialState:
documentContents: |
a
Expand Down Expand Up @@ -58,4 +58,4 @@ finalState:
sourceMark:
- anchor: {line: 0, character: 0}
active: {line: 0, character: 1}
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}}}]
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}}}]
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
languageId: plaintext
command:
version: 1
spokenForm: post bat vertical until fine
action: setSelectionAfter
targets:
- type: range
start:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: b}
end:
type: primitive
mark: {type: decoratedSymbol, symbolColor: default, character: f}
excludeStart: false
excludeEnd: true
rangeType: vertical
initialState:
documentContents: |
a
b c
d e
f g
selections:
- anchor: {line: 5, character: 0}
active: {line: 5, character: 0}
marks:
default.b:
start: {line: 2, character: 0}
end: {line: 2, character: 1}
default.f:
start: {line: 4, character: 0}
end: {line: 4, character: 1}
finalState:
documentContents: |
a
b c
d e
f g
selections:
- anchor: {line: 2, character: 1}
active: {line: 2, character: 1}
- anchor: {line: 3, character: 1}
active: {line: 3, character: 1}
thatMark:
- anchor: {line: 2, character: 0}
active: {line: 2, character: 1}
- anchor: {line: 3, character: 0}
active: {line: 3, character: 1}
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}}}]
Loading

0 comments on commit 66f160e

Please sign in to comment.