mirror of
https://github.com/microsoft/vscode.git
synced 2026-06-06 15:45:54 +01:00
commit characters must check suggest model state before proceeding (#163467)
fixes https://github.com/microsoft/vscode/issues/163431
This commit is contained in:
@@ -8,6 +8,7 @@ import { DisposableStore } from 'vs/base/common/lifecycle';
|
||||
import { ICodeEditor } from 'vs/editor/browser/editorBrowser';
|
||||
import { EditorOption } from 'vs/editor/common/config/editorOptions';
|
||||
import { CharacterSet } from 'vs/editor/common/core/characterClassifier';
|
||||
import { State, SuggestModel } from 'vs/editor/contrib/suggest/browser/suggestModel';
|
||||
import { ISelectedSuggestion, SuggestWidget } from './suggestWidget';
|
||||
|
||||
export class CommitCharacterController {
|
||||
@@ -19,14 +20,23 @@ export class CommitCharacterController {
|
||||
readonly item: ISelectedSuggestion;
|
||||
};
|
||||
|
||||
constructor(editor: ICodeEditor, widget: SuggestWidget, accept: (selected: ISelectedSuggestion) => any) {
|
||||
constructor(editor: ICodeEditor, widget: SuggestWidget, model: SuggestModel, accept: (selected: ISelectedSuggestion) => any) {
|
||||
|
||||
this._disposables.add(model.onDidSuggest(e => {
|
||||
if (e.completionModel.items.length === 0) {
|
||||
this.reset();
|
||||
}
|
||||
}));
|
||||
this._disposables.add(model.onDidCancel(e => {
|
||||
this.reset();
|
||||
}));
|
||||
|
||||
this._disposables.add(widget.onDidShow(() => this._onItem(widget.getFocusedItem())));
|
||||
this._disposables.add(widget.onDidFocus(this._onItem, this));
|
||||
this._disposables.add(widget.onDidHide(this.reset, this));
|
||||
|
||||
this._disposables.add(editor.onWillType(text => {
|
||||
if (this._active && !widget.isFrozen()) {
|
||||
if (this._active && !widget.isFrozen() && model.state !== State.Idle) {
|
||||
const ch = text.charCodeAt(text.length - 1);
|
||||
if (this._active.acceptCharacters.has(ch) && editor.getOption(EditorOption.acceptSuggestionOnCommitCharacter)) {
|
||||
accept(this._active.item);
|
||||
|
||||
@@ -47,8 +47,9 @@ import { basename, extname } from 'vs/base/common/resources';
|
||||
import { hash } from 'vs/base/common/hash';
|
||||
|
||||
// sticky suggest widget which doesn't disappear on focus out and such
|
||||
const _sticky = false;
|
||||
// _sticky = Boolean("true"); // done "weirdly" so that a lint warning prevents you from pushing this
|
||||
const _sticky = false
|
||||
// || Boolean("true") // done "weirdly" so that a lint warning prevents you from pushing this
|
||||
;
|
||||
|
||||
class LineSuffix {
|
||||
|
||||
@@ -142,13 +143,9 @@ export class SuggestController implements IEditorContribution {
|
||||
this._toDispose.add(widget.onDidSelect(item => this._insertSuggestion(item, 0), this));
|
||||
|
||||
// Wire up logic to accept a suggestion on certain characters
|
||||
const commitCharacterController = new CommitCharacterController(this.editor, widget, item => this._insertSuggestion(item, InsertFlags.NoAfterUndoStop));
|
||||
const commitCharacterController = new CommitCharacterController(this.editor, widget, this.model, item => this._insertSuggestion(item, InsertFlags.NoAfterUndoStop));
|
||||
this._toDispose.add(commitCharacterController);
|
||||
this._toDispose.add(this.model.onDidSuggest(e => {
|
||||
if (e.completionModel.items.length === 0) {
|
||||
commitCharacterController.reset();
|
||||
}
|
||||
}));
|
||||
|
||||
|
||||
// Wire up makes text edit context key
|
||||
const ctxMakesTextEdit = SuggestContext.MakesTextEdit.bindTo(this._contextKeyService);
|
||||
|
||||
Reference in New Issue
Block a user