mirror of
https://github.com/microsoft/vscode.git
synced 2026-08-04 20:36:01 +01:00
fix #27541
* return `undefined` when current word or selection is falsy * use editor selection, not snippet selection, when resolving variables
This commit is contained in:
@@ -253,7 +253,7 @@ export class SnippetSession {
|
||||
const start = snippetSelection.getStartPosition();
|
||||
const adjustedTemplate = SnippetSession.adjustWhitespace(model, start, this._template);
|
||||
|
||||
const snippet = SnippetParser.parse(adjustedTemplate).resolveVariables(new EditorSnippetVariableResolver(model, snippetSelection));
|
||||
const snippet = SnippetParser.parse(adjustedTemplate).resolveVariables(new EditorSnippetVariableResolver(model, selection));
|
||||
|
||||
// rewrite final-tabstop to some other placeholder because this
|
||||
// snippet sits inside another snippet
|
||||
|
||||
@@ -32,7 +32,7 @@ export class EditorSnippetVariableResolver {
|
||||
|
||||
resolve(name: string): string {
|
||||
if (name === 'SELECTION' || name === 'TM_SELECTED_TEXT') {
|
||||
return this._model.getValueInRange(this._selection);
|
||||
return this._model.getValueInRange(this._selection) || undefined;
|
||||
|
||||
} else if (name === 'TM_CURRENT_LINE') {
|
||||
return this._model.getLineContent(this._selection.positionLineNumber);
|
||||
@@ -42,7 +42,7 @@ export class EditorSnippetVariableResolver {
|
||||
lineNumber: this._selection.positionLineNumber,
|
||||
column: this._selection.positionColumn
|
||||
});
|
||||
return info ? info.word : '';
|
||||
return info && info.word || undefined;
|
||||
|
||||
} else if (name === 'TM_LINE_INDEX') {
|
||||
return String(this._selection.positionLineNumber - 1);
|
||||
|
||||
@@ -78,12 +78,12 @@ suite('Snippet Variables Resolver', function () {
|
||||
assert.equal(resolver.resolve('TM_LINE_NUMBER'), '1');
|
||||
|
||||
resolver = new EditorSnippetVariableResolver(model, new Selection(1, 2, 1, 2));
|
||||
assert.equal(resolver.resolve('TM_SELECTED_TEXT'), '');
|
||||
assert.equal(resolver.resolve('TM_SELECTED_TEXT'), undefined);
|
||||
|
||||
assert.equal(resolver.resolve('TM_CURRENT_WORD'), 'this');
|
||||
|
||||
resolver = new EditorSnippetVariableResolver(model, new Selection(3, 1, 3, 1));
|
||||
assert.equal(resolver.resolve('TM_CURRENT_WORD'), '');
|
||||
assert.equal(resolver.resolve('TM_CURRENT_WORD'), undefined);
|
||||
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user