提交 b99471e2 编写于 作者: M Matt Bierner

Use more explicit state for CharacterOracle

上级 2c3351df
......@@ -37,8 +37,10 @@ class AcceptOnCharacterOracle {
private _disposables: IDisposable[] = [];
private _activeAcceptCharacters = new CharacterSet();
private _activeItem: ISelectedSuggestion;
private _active?: {
readonly acceptCharacters: CharacterSet;
readonly item: ISelectedSuggestion;
};
constructor(editor: ICodeEditor, widget: SuggestWidget, accept: (selected: ISelectedSuggestion) => any) {
......@@ -47,10 +49,10 @@ class AcceptOnCharacterOracle {
this._disposables.push(widget.onDidHide(this.reset, this));
this._disposables.push(editor.onWillType(text => {
if (this._activeItem) {
if (this._active) {
const ch = text.charCodeAt(text.length - 1);
if (this._activeAcceptCharacters.has(ch) && editor.getConfiguration().contribInfo.acceptSuggestionOnCommitCharacter) {
accept(this._activeItem);
if (this._active.acceptCharacters.has(ch) && editor.getConfiguration().contribInfo.acceptSuggestionOnCommitCharacter) {
accept(this._active.item);
}
}
}));
......@@ -61,17 +63,18 @@ class AcceptOnCharacterOracle {
this.reset();
return;
}
this._activeItem = selected;
this._activeAcceptCharacters = new CharacterSet();
const acceptCharacters = new CharacterSet();
for (const ch of selected.item.completion.commitCharacters) {
if (ch.length > 0) {
this._activeAcceptCharacters.add(ch.charCodeAt(0));
acceptCharacters.add(ch.charCodeAt(0));
}
}
this._active = { acceptCharacters, item: selected };
}
reset(): void {
this._activeItem = undefined;
this._active = undefined;
}
dispose() {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册