aboutsummaryrefslogtreecommitdiff
path: root/editors/code
diff options
context:
space:
mode:
authorJonas Schievink <[email protected]>2021-03-27 17:50:55 +0000
committerJonas Schievink <[email protected]>2021-03-27 17:50:55 +0000
commit201fbac8a97ba240ba6112c8f3ceca9ed1f23a3d (patch)
treea42dff4c49d713a6d57140800d3dd3254a7d3dcc /editors/code
parente39979aa91c8c08219e35a74ae5aa7aa5d8bc4d6 (diff)
Fix handling of multi-cursor snippets
This allows one snippet per TextEdit, multiple in the same TextEdit are still broken
Diffstat (limited to 'editors/code')
-rw-r--r--editors/code/src/snippets.ts10
1 files changed, 5 insertions, 5 deletions
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts
index dc53ebe2e..c8e71341a 100644
--- a/editors/code/src/snippets.ts
+++ b/editors/code/src/snippets.ts
@@ -29,7 +29,7 @@ async function editorFromUri(uri: vscode.Uri): Promise<vscode.TextEditor | undef
29} 29}
30 30
31export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) { 31export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) {
32 let selection: vscode.Selection | undefined = undefined; 32 let selections: vscode.Selection[] = [];
33 let lineDelta = 0; 33 let lineDelta = 0;
34 await editor.edit((builder) => { 34 await editor.edit((builder) => {
35 for (const indel of edits) { 35 for (const indel of edits) {
@@ -44,18 +44,18 @@ export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vs
44 indel.range.start.character + placeholderStart 44 indel.range.start.character + placeholderStart
45 : prefix.length - lastNewline - 1; 45 : prefix.length - lastNewline - 1;
46 const endColumn = startColumn + placeholderLength; 46 const endColumn = startColumn + placeholderLength;
47 selection = new vscode.Selection( 47 selections.push(new vscode.Selection(
48 new vscode.Position(startLine, startColumn), 48 new vscode.Position(startLine, startColumn),
49 new vscode.Position(startLine, endColumn), 49 new vscode.Position(startLine, endColumn),
50 ); 50 ));
51 builder.replace(indel.range, newText); 51 builder.replace(indel.range, newText);
52 } else { 52 } else {
53 lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line);
54 builder.replace(indel.range, indel.newText); 53 builder.replace(indel.range, indel.newText);
55 } 54 }
55 lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line);
56 } 56 }
57 }); 57 });
58 if (selection) editor.selection = selection; 58 if (selections.length > 0) editor.selections = selections;
59} 59}
60 60
61function parseSnippet(snip: string): [string, [number, number]] | undefined { 61function parseSnippet(snip: string): [string, [number, number]] | undefined {