From bd3beec0429a3f5ec3c4a2b5f6bf3c42e6910ef2 Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Wed, 11 Jul 2018 08:56:57 -0700 Subject: [PATCH] Extract getInsertionPositions --- .../src/features/tagCompletion.ts | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/extensions/typescript-language-features/src/features/tagCompletion.ts b/extensions/typescript-language-features/src/features/tagCompletion.ts index 3843c486f87..66af4920ef9 100644 --- a/extensions/typescript-language-features/src/features/tagCompletion.ts +++ b/extensions/typescript-language-features/src/features/tagCompletion.ts @@ -114,13 +114,9 @@ class TagClosing { const activeDocument = activeEditor.document; if (document === activeDocument && activeDocument.version === version) { - const selections = activeEditor.selections; - const snippet = this.getTagSnippet(body); - if (selections.length && selections.some(s => s.active.isEqual(position))) { - activeEditor.insertSnippet(snippet, selections.map(s => s.active)); - } else { - activeEditor.insertSnippet(snippet, position); - } + activeEditor.insertSnippet( + this.getTagSnippet(body), + this.getInsertionPositions(activeEditor, position)); } }, 100); } @@ -131,6 +127,13 @@ class TagClosing { snippet.appendText(closingTag.newText); return snippet; } + + private getInsertionPositions(editor: vscode.TextEditor, position: vscode.Position) { + const activeSelectionPositions = editor.selections.map(s => s.active); + return activeSelectionPositions.some(p => p.isEqual(position)) + ? activeSelectionPositions + : position; + } } export class ActiveDocumentDependentRegistration {