mirror of
https://github.com/Microsoft/vscode
synced 2024-10-30 21:06:57 +00:00
stricter definition for what a trival snippet it (#165355)
fixes https://github.com/microsoft/vscode/issues/163808
This commit is contained in:
parent
46face3cc7
commit
16f30d90d2
3 changed files with 37 additions and 2 deletions
|
@ -165,6 +165,13 @@ export abstract class Marker {
|
|||
return this._children;
|
||||
}
|
||||
|
||||
get rightMostDescendant(): Marker {
|
||||
if (this._children.length > 0) {
|
||||
return this._children[this._children.length - 1].rightMostDescendant;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
get snippet(): TextmateSnippet | undefined {
|
||||
let candidate: Marker = this;
|
||||
while (true) {
|
||||
|
|
|
@ -208,9 +208,23 @@ export class OneSnippet {
|
|||
return this._snippet.placeholders.length > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* A snippet is trivial when it has no placeholder or only a final placeholder at
|
||||
* its very end
|
||||
*/
|
||||
get isTrivialSnippet(): boolean {
|
||||
return this._snippet.placeholders.length === 0
|
||||
|| (this._snippet.placeholders.length === 1 && this._snippet.placeholders[0].isFinalTabstop);
|
||||
if (this._snippet.placeholders.length === 0) {
|
||||
return true;
|
||||
}
|
||||
if (this._snippet.placeholders.length === 1) {
|
||||
const [placeholder] = this._snippet.placeholders;
|
||||
if (placeholder.isFinalTabstop) {
|
||||
if (this._snippet.rightMostDescendant === placeholder) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
computePossibleSelections() {
|
||||
|
|
|
@ -692,4 +692,18 @@ suite('SnippetController2', function () {
|
|||
assert.deepStrictEqual(editor.getSelections(), [new Selection(1, 5, 1, 5), new Selection(1, 10, 1, 10), new Selection(2, 5, 2, 5), new Selection(2, 10, 2, 10)]);
|
||||
});
|
||||
});
|
||||
|
||||
test('Bug: cursor position $0 with user snippets #163808', function () {
|
||||
|
||||
const ctrl = instaService.createInstance(SnippetController2, editor);
|
||||
model.setValue('');
|
||||
|
||||
ctrl.insert('<Element1 Attr1="foo" $1>\n <Element2 Attr1="$2"/>\n$0"\n</Element1>');
|
||||
assert.deepStrictEqual(editor.getSelections(), [new Selection(1, 23, 1, 23)]);
|
||||
|
||||
ctrl.insert('Qualifier="$0"');
|
||||
assert.strictEqual(model.getValue(), '<Element1 Attr1="foo" Qualifier="">\n <Element2 Attr1=""/>\n"\n</Element1>');
|
||||
assert.deepStrictEqual(editor.getSelections(), [new Selection(1, 34, 1, 34)]);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue