提交 432487e1 编写于 作者: J Johannes Rieken

better choice handling, #17545

上级 eddd1f09
......@@ -14,6 +14,8 @@ import { EditorContextKeys } from 'vs/editor/common/editorContextKeys';
import { KeyCode, KeyMod } from 'vs/base/common/keyCodes';
import { showSimpleSuggestions } from 'vs/editor/contrib/suggest/browser/suggest';
import { ISuggestion } from 'vs/editor/common/modes';
import { Selection } from 'vs/editor/common/core/selection';
import { Choice } from 'vs/editor/contrib/snippet/browser/snippetParser';
@commonEditorContribution
export class SnippetController2 {
......@@ -33,6 +35,7 @@ export class SnippetController2 {
private _session: SnippetSession;
private _snippetListener: IDisposable[] = [];
private _modelVersionId: number;
private _currentChoice: Choice;
constructor(
private readonly _editor: ICommonCodeEditor,
......@@ -113,17 +116,39 @@ export class SnippetController2 {
this._hasPrevTabstop.set(!this._session.isAtFirstPlaceholder);
this._hasNextTabstop.set(!this._session.isAtLastPlaceholder);
this._handleChoice();
}
private _handleChoice(): void {
const { choice } = this._session;
if (choice) {
const suggestions = choice.options.map((option, i) => {
if (!choice) {
this._currentChoice = undefined;
return;
}
if (this._currentChoice !== choice) {
this._currentChoice = choice;
this._editor.setSelections(this._editor.getSelections()
.map(s => Selection.fromPositions(s.getStartPosition()))
);
const [first] = choice.options;
showSimpleSuggestions(this._editor, choice.options.map((option, i) => {
// let before = choice.options.slice(0, i);
// let after = choice.options.slice(i);
return <ISuggestion>{
type: 'value',
label: option.value,
insertText: option.value,
type: 'value',
sortText: String(i)
// insertText: `\${1|${after.concat(before).join(',')}|}$0`,
// snippetType: 'textmate',
sortText: String(i),
overwriteAfter: first.value.length
};
});
showSimpleSuggestions(this._editor, suggestions);
}));
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册