提交 a6d74abc 编写于 作者: J Johannes Rieken

add failing test, fix test, the feature is actually not done. thi is so tdd - #9764

上级 3e87aced
......@@ -59,6 +59,27 @@ export class CodeSnippet implements ICodeSnippet {
this.parseTemplate(snippetTemplate);
}
get isInsertOnly(): boolean {
return this.placeHolders.length === 0;
}
get isSingleTabstopOnly(): boolean {
if (this.placeHolders.length !== 1) {
return false;
}
const [placeHolder] = this.placeHolders;
if (placeHolder.value !== '' || placeHolder.occurences.length !== 1) {
return false;
}
const [placeHolderRange] = placeHolder.occurences;
if (!Range.isEmpty(placeHolderRange)) {
return false;
}
return true;
}
private parseTemplate(template: string): void {
var placeHoldersMap: collections.IStringDictionary<IPlaceHolder> = {};
......
......@@ -380,9 +380,11 @@ export class SnippetController {
public run(snippet: CodeSnippet, overwriteBefore: number, overwriteAfter: number, stripPrefix?: boolean): void {
this._runAndRestoreController(() => {
if (snippet.placeHolders.length === 0) {
// No placeholders => execute for all editor selections
if (snippet.isInsertOnly || snippet.isSingleTabstopOnly) {
// Only inserts text, not placeholders, tabstops etc
// Only cursor endposition
this._runForAllSelections(snippet, overwriteBefore, overwriteAfter, stripPrefix);
} else {
let prepared = SnippetController._prepareSnippet(this._editor, this._editor.getSelection(), snippet, overwriteBefore, overwriteAfter, stripPrefix);
this._runPreparedSnippetForPrimarySelection(prepared, true);
......
......@@ -7,6 +7,7 @@
import * as assert from 'assert';
import {Range} from 'vs/editor/common/core/range';
import {Position} from 'vs/editor/common/core/position';
import {Selection} from 'vs/editor/common/core/selection';
import {CodeSnippet} from 'vs/editor/contrib/snippet/common/snippet';
import {SnippetController} from 'vs/editor/contrib/snippet/common/snippetController';
import {MockCodeEditor, withMockCodeEditor} from 'vs/editor/test/common/mocks/mockCodeEditor';
......@@ -219,4 +220,21 @@ suite('SnippetController', () => {
assert.equal(snippetController.isInSnippetMode(), false);
});
});
test('Final tabstop with multiple selection', () => {
snippetTest((editor, cursor, codeSnippet, snippetController) => {
editor.setSelections([
new Selection(1, 1, 1, 1),
new Selection(2, 1, 2, 1),
]);
codeSnippet = new CodeSnippet('foo{{}}');
snippetController.run(codeSnippet, 0, 0, false);
assert.equal(editor.getSelections().length, 2);
const [first, second] = editor.getSelections();
assert.ok(first.equalsRange({ startLineNumber: 1, startColumn: 4, endLineNumber: 1, endColumn: 4 }));
assert.ok(second.equalsRange({ startLineNumber: 2, startColumn: 4, endLineNumber: 2, endColumn: 4 }));
});
});
});
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册