|
6 | 6 | *--------------------------------------------------------------------------------------------*/ |
7 | 7 | 'use strict'; |
8 | 8 |
|
9 | | -import { window, workspace, Disposable, TextDocumentContentChangeEvent, TextDocument, Position, SnippetString } from 'vscode'; |
| 9 | +import { window, workspace, Disposable, TextDocumentContentChangeEvent, TextDocument, Position, SnippetString, Range } from 'vscode'; |
10 | 10 |
|
11 | | -export function activateTagClosing(tagProvider: (document: TextDocument, position: Position) => Thenable<string>, supportedLanguages: { [id: string]: boolean }, configName: string): Disposable { |
| 11 | +export interface AutoCloseResult { |
| 12 | + snippet: string, |
| 13 | + range?: Range |
| 14 | +} |
| 15 | + |
| 16 | +export function activateTagClosing(tagProvider: (document: TextDocument, position: Position) => Thenable<AutoCloseResult>, supportedLanguages: { [id: string]: boolean }, configName: string): Disposable { |
12 | 17 |
|
13 | 18 | let disposables: Disposable[] = []; |
14 | 19 | workspace.onDidChangeTextDocument(event => onDidChangeTextDocument(event.document, event.contentChanges), null, disposables); |
@@ -57,18 +62,29 @@ export function activateTagClosing(tagProvider: (document: TextDocument, positio |
57 | 62 | let version = document.version; |
58 | 63 | timeout = setTimeout(() => { |
59 | 64 | let position = new Position(rangeStart.line, rangeStart.character + lastChange.text.length); |
60 | | - tagProvider(document, position).then(text => { |
| 65 | + tagProvider(document, position).then(result => { |
| 66 | + let text = result.snippet; |
| 67 | + let replaceLocation : Position | Range; |
| 68 | + let range : Range = result.range; |
| 69 | + if(range != null) { |
| 70 | + // re-create Range |
| 71 | + let line = range.start.line; |
| 72 | + let character = range.start.character; |
| 73 | + let startPosition = new Position(line, character); |
| 74 | + line = range.end.line; |
| 75 | + character = range.end.character; |
| 76 | + let endPosition = new Position(line, character); |
| 77 | + replaceLocation = new Range(startPosition, endPosition); |
| 78 | + } |
| 79 | + else { |
| 80 | + replaceLocation = position; |
| 81 | + } |
61 | 82 | if (text && isEnabled) { |
62 | 83 | let activeEditor = window.activeTextEditor; |
63 | 84 | if (activeEditor) { |
64 | 85 | let activeDocument = activeEditor.document; |
65 | 86 | if (document === activeDocument && activeDocument.version === version) { |
66 | | - let selections = activeEditor.selections; |
67 | | - if (selections.length && selections.some(s => s.active.isEqual(position))) { |
68 | | - activeEditor.insertSnippet(new SnippetString(text), selections.map(s => s.active)); |
69 | | - } else { |
70 | | - activeEditor.insertSnippet(new SnippetString(text), position); |
71 | | - } |
| 87 | + activeEditor.insertSnippet(new SnippetString(text), replaceLocation); |
72 | 88 | } |
73 | 89 | } |
74 | 90 | } |
|
0 commit comments