Skip to content

Commit c89158c

Browse files
committed
Attempt to make new raw selections work
1 parent 1db4216 commit c89158c

File tree

8 files changed

+51
-25
lines changed

8 files changed

+51
-25
lines changed

.vscode/settings.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
// Turn off tsc task auto detection since we have the necessary tasks as npm scripts
1313
"typescript.tsc.autoDetect": "off",
1414
"cSpell.words": [
15-
"subword",
15+
"Autoformatting",
1616
"eqeqeq",
1717
"nonlocal",
18-
"pojo"
18+
"pojo",
19+
"subword"
1920
]
2021
}

src/actions/BringMoveSwap.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,10 @@ class BringMoveSwap implements Action {
115115
let text = source.selection.editor.document.getText(
116116
source.selection.selection
117117
);
118-
const selectionContext =
119-
destination.selectionType === "strictHere"
120-
? source.selectionContext
121-
: destination.selectionContext;
118+
const selectionContext = destination.selectionContext
119+
.isRawSelection
120+
? source.selectionContext
121+
: destination.selectionContext;
122122
return i > 0 && selectionContext.containingListDelimiter
123123
? selectionContext.containingListDelimiter + text
124124
: text;

src/core/inferFullTargets.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@ function inferPrimitiveTarget(
9494
previousTargets: PartialTarget[],
9595
actionPreferences: ActionPreferences
9696
): PrimitiveTarget {
97-
const previousTargetsForAttributes = hasContent(target)
98-
? []
99-
: previousTargets;
97+
const doAttributeInference = !hasContent(target) && !target.isImplicit;
98+
99+
const previousTargetsForAttributes = doAttributeInference
100+
? previousTargets
101+
: [];
100102

101103
const maybeSelectionType =
102104
target.selectionType ??
@@ -117,7 +119,7 @@ function inferPrimitiveTarget(
117119

118120
const selectionType =
119121
maybeSelectionType ??
120-
(target.modifier == null ? actionPreferences.selectionType : null) ??
122+
(doAttributeInference ? actionPreferences.selectionType : null) ??
121123
"token";
122124

123125
const insideOutsideType =
@@ -127,7 +129,7 @@ function inferPrimitiveTarget(
127129

128130
const modifier = target.modifier ??
129131
getPreviousAttribute(previousTargetsForAttributes, "modifier") ??
130-
(target.selectionType == null ? actionPreferences.modifier : null) ?? {
132+
(doAttributeInference ? actionPreferences.modifier : null) ?? {
131133
type: "identity",
132134
};
133135

@@ -138,6 +140,7 @@ function inferPrimitiveTarget(
138140
position,
139141
insideOutsideType,
140142
modifier,
143+
isImplicit: target.isImplicit ?? false,
141144
};
142145
}
143146

src/processTargets/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,13 @@ function processPrimitiveTarget(
274274
({ selection, context: selectionContext }) =>
275275
processSelectionType(context, target, selection, selectionContext)
276276
);
277+
278+
if (target.isImplicit) {
279+
typedSelections.forEach((typedSelection) => {
280+
typedSelection.selectionContext.isRawSelection = true;
281+
});
282+
}
283+
277284
return typedSelections.map((selection) =>
278285
processPosition(context, target, selection)
279286
);

src/processTargets/modifiers/processModifier.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
NodeMatcher,
1111
PrimitiveTarget,
1212
ProcessedTargetsContext,
13+
RawSelectionModifier,
1314
SelectionContext,
1415
SelectionWithEditor,
1516
SubTokenModifier,
@@ -52,6 +53,14 @@ export default function (
5253
case "surroundingPair":
5354
result = processSurroundingPair(context, selection, modifier);
5455
break;
56+
57+
case "toRawSelection":
58+
result = processRawSelectionModifier(context, selection, modifier);
59+
break;
60+
61+
default:
62+
// Make sure we haven't missed any cases
63+
const neverCheck: never = modifier;
5564
}
5665

5766
if (result == null) {
@@ -233,3 +242,16 @@ export function findNearestContainingAncestorNode(
233242

234243
return null;
235244
}
245+
246+
function processRawSelectionModifier(
247+
context: ProcessedTargetsContext,
248+
selection: SelectionWithEditor,
249+
modifier: RawSelectionModifier
250+
): SelectionWithEditorWithContext[] | null {
251+
return [
252+
{
253+
selection,
254+
context: { isRawSelection: true },
255+
},
256+
];
257+
}

src/processTargets/processSelectionType.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ export default function (
3333
return processLine(target, selection, selectionContext);
3434
case "paragraph":
3535
return processParagraph(target, selection, selectionContext);
36-
case "strictHere":
37-
return processStrictHere(target, selection, selectionContext);
3836
}
3937
}
4038

src/typings/Types.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,7 @@ export type Modifier =
184184

185185
export type SelectionType =
186186
// | "character" Not implemented
187-
| "token"
188-
| "line"
189-
| "notebookCell"
190-
| "paragraph"
191-
| "document"
192-
| "column"
193-
| "strictHere";
187+
"token" | "line" | "notebookCell" | "paragraph" | "document";
194188

195189
export type Position = "before" | "after" | "contents";
196190

src/util/canonicalizeTargets.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,15 @@ const STRICT_HERE = {
5252
insideOutsideType: "inside",
5353
};
5454

55+
const IMPLICIT_TARGET: PartialPrimitiveTarget = {
56+
type: "primitive",
57+
isImplicit: true,
58+
};
59+
5560
const upgradeStrictHere = (
5661
target: PartialPrimitiveTarget
5762
): PartialPrimitiveTarget =>
58-
isDeepStrictEqual(target, STRICT_HERE)
59-
? update(target, {
60-
selectionType: () => "strictHere",
61-
})
62-
: target;
63+
isDeepStrictEqual(target, STRICT_HERE) ? IMPLICIT_TARGET : target;
6364

6465
export default function canonicalizeTargets(partialTargets: PartialTarget[]) {
6566
return transformPartialPrimitiveTargets(

0 commit comments

Comments
 (0)