diff options
| author | Jonas Schievink <jonasschievink@gmail.com> | 2021-03-27 18:50:55 +0100 |
|---|---|---|
| committer | Jonas Schievink <jonasschievink@gmail.com> | 2021-03-27 18:50:55 +0100 |
| commit | 201fbac8a97ba240ba6112c8f3ceca9ed1f23a3d (patch) | |
| tree | a42dff4c49d713a6d57140800d3dd3254a7d3dcc /editors/code | |
| parent | e39979aa91c8c08219e35a74ae5aa7aa5d8bc4d6 (diff) | |
| download | rust-201fbac8a97ba240ba6112c8f3ceca9ed1f23a3d.tar.gz rust-201fbac8a97ba240ba6112c8f3ceca9ed1f23a3d.zip | |
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.ts | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/editors/code/src/snippets.ts b/editors/code/src/snippets.ts index dc53ebe2eeb..c8e71341a7d 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 } export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vscode.TextEdit[]) { - let selection: vscode.Selection | undefined = undefined; + let selections: vscode.Selection[] = []; let lineDelta = 0; await editor.edit((builder) => { for (const indel of edits) { @@ -44,18 +44,18 @@ export async function applySnippetTextEdits(editor: vscode.TextEditor, edits: vs indel.range.start.character + placeholderStart : prefix.length - lastNewline - 1; const endColumn = startColumn + placeholderLength; - selection = new vscode.Selection( + selections.push(new vscode.Selection( new vscode.Position(startLine, startColumn), new vscode.Position(startLine, endColumn), - ); + )); builder.replace(indel.range, newText); } else { - lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line); builder.replace(indel.range, indel.newText); } + lineDelta = countLines(indel.newText) - (indel.range.end.line - indel.range.start.line); } }); - if (selection) editor.selection = selection; + if (selections.length > 0) editor.selections = selections; } function parseSnippet(snip: string): [string, [number, number]] | undefined { |
