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

Use more explicit state for CharacterOracle

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