Skip to content

Commit 117af66

Browse files
Support wrapping snippet placeholders (#1999)
Support wrapping placeholders/numbered holes in snippets ## Checklist - [x] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet
1 parent 7242370 commit 117af66

File tree

2 files changed

+44
-0
lines changed
  • packages
    • cursorless-engine/src/snippets
    • cursorless-vscode-e2e/src/suite/fixtures/recorded/actions/snippets

2 files changed

+44
-0
lines changed

packages/cursorless-engine/src/snippets/snippet.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ export function transformSnippetVariables(
5353
candidate.children.forEach((child) => placeholder.appendChild(child));
5454
candidate.parent.replace(candidate, [placeholder]);
5555
}
56+
} else if (candidate instanceof Placeholder) {
57+
if (candidate.index.toString() === placeholderName) {
58+
candidate.parent.replace(candidate, [new Variable("TM_SELECTED_TEXT")]);
59+
}
5660
}
5761
return true;
5862
});
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
languageId: typescript
2+
command:
3+
version: 6
4+
spokenForm: if wrap cap
5+
action:
6+
name: wrapWithSnippet
7+
snippetDescription:
8+
type: custom
9+
body: "if ($1) {\n\t$0\n}"
10+
scopeType: {type: statement}
11+
variableName: "0"
12+
target:
13+
type: primitive
14+
mark: {type: decoratedSymbol, symbolColor: default, character: c}
15+
usePrePhraseSnapshot: true
16+
spokenFormError: Custom wrap with snippet
17+
initialState:
18+
documentContents: const value = 2;
19+
selections:
20+
- anchor: {line: 0, character: 0}
21+
active: {line: 0, character: 0}
22+
marks:
23+
default.c:
24+
start: {line: 0, character: 0}
25+
end: {line: 0, character: 5}
26+
finalState:
27+
documentContents: |-
28+
if () {
29+
const value = 2;
30+
}
31+
selections:
32+
- anchor: {line: 0, character: 4}
33+
active: {line: 0, character: 4}
34+
thatMark:
35+
- type: UntypedTarget
36+
contentRange:
37+
start: {line: 0, character: 0}
38+
end: {line: 2, character: 1}
39+
isReversed: false
40+
hasExplicitRange: true

0 commit comments

Comments
 (0)