Skip to content

Commit 201fbac

Browse files
Fix handling of multi-cursor snippets
This allows one snippet per TextEdit, multiple in the same TextEdit are still broken
1 parent e39979a commit 201fbac

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

editors/code/src/snippets.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async function editorFromUri(uri: vscode.Uri): Promise<vscode.TextEditor | undef
2929
}
3030

3131
export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) {
32-
let selection: vscode.Selection | undefined = undefined;
32+
let selections: vscode.Selection[] = [];
3333
let lineDelta = 0;
3434
await editor.edit((builder) => {
3535
for (const indel of edits) {
@@ -44,18 +44,18 @@ export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vs
4444
indel.range.start.character + placeholderStart
4545
: prefix.length - lastNewline - 1;
4646
const endColumn = startColumn + placeholderLength;
47-
selection = new vscode.Selection(
47+
selections.push(new vscode.Selection(
4848
new vscode.Position(startLine, startColumn),
4949
new vscode.Position(startLine, endColumn),
50-
);
50+
));
5151
builder.replace(indel.range, newText);
5252
} else {
53-
lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line);
5453
builder.replace(indel.range, indel.newText);
5554
}
55+
lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line);
5656
}
5757
});
58-
if (selection) editor.selection = selection;
58+
if (selections.length > 0) editor.selections = selections;
5959
}
6060

6161
function parseSnippet(snip: string): [string, [number, number]] | undefined {

0 commit comments

Comments
 (0)