From 2461331b4fab7f1c00c213cd3980128541da1bf9 Mon Sep 17 00:00:00 2001 From: Joao Moreno Date: Mon, 8 Feb 2016 16:13:34 +0100 Subject: [PATCH] suggest: fix details issue --- src/vs/base/browser/ui/list/listWidget.ts | 8 +- .../contrib/suggest/browser/suggestWidget.ts | 86 +++++++------------ 2 files changed, 33 insertions(+), 61 deletions(-) diff --git a/src/vs/base/browser/ui/list/listWidget.ts b/src/vs/base/browser/ui/list/listWidget.ts index c1ae028d323..1188be376b2 100644 --- a/src/vs/base/browser/ui/list/listWidget.ts +++ b/src/vs/base/browser/ui/list/listWidget.ts @@ -218,7 +218,7 @@ export class List implements IDisposable { if (this.length === 0) return; const selection = this.selection.get(); let index = selection.length > 0 ? selection[0] + n : 0; - this.selection.set(loop ? index % this.length : Math.min(index, this.length - 1)); + this.setSelection(loop ? index % this.length : Math.min(index, this.length - 1)); } selectPrevious(n = 1, loop = false): void { @@ -226,7 +226,7 @@ export class List implements IDisposable { const selection = this.selection.get(); let index = selection.length > 0 ? selection[0] - n : 0; if (loop && index < 0) index = this.length + (index % this.length); - this.selection.set(Math.max(index, 0)); + this.setSelection(Math.max(index, 0)); } setFocus(...indexes: number[]): void { @@ -238,7 +238,7 @@ export class List implements IDisposable { if (this.length === 0) return; const focus = this.focus.get(); let index = focus.length > 0 ? focus[0] + n : 0; - this.focus.set(loop ? index % this.length : Math.min(index, this.length - 1)); + this.setFocus(loop ? index % this.length : Math.min(index, this.length - 1)); } focusPrevious(n = 1, loop = false): void { @@ -246,7 +246,7 @@ export class List implements IDisposable { const focus = this.focus.get(); let index = focus.length > 0 ? focus[0] - n : 0; if (loop && index < 0) index = this.length + (index % this.length); - this.focus.set(Math.max(index, 0)); + this.setFocus(Math.max(index, 0)); } focusNextPage(): void { diff --git a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts index ba985157f1d..f689341b7db 100644 --- a/src/vs/editor/contrib/suggest/browser/suggestWidget.ts +++ b/src/vs/editor/contrib/suggest/browser/suggestWidget.ts @@ -64,8 +64,6 @@ class CompletionItem { support: ISuggestSupport; container: ISuggestResult; - private _resolveDetails: TPromise; - constructor(public group: CompletionGroup, suggestion: ISuggestion, container: ISuggestResult2) { this.id = String(CompletionItem._idPool++); this.support = container.support; @@ -73,22 +71,16 @@ class CompletionItem { this.container = container; } - resolveDetails(resource: URI, position: EditorCommon.IPosition): TPromise { - if (this._resolveDetails) { - return this._resolveDetails; - } - + resolveDetails(resource: URI, position: EditorCommon.IPosition): TPromise { if (!this.support || typeof this.support.getSuggestionDetails !== 'function') { - return this._resolveDetails = TPromise.as(this); + return TPromise.as(this.suggestion); } - return this._resolveDetails = this.support - .getSuggestionDetails(resource, position, this.suggestion) - .then( - value => this.suggestion = assign(this.suggestion, value), - err => isPromiseCanceledError(err) ? this._resolveDetails = null : onUnexpectedError(err) - ) - .then(() => this); + return this.support.getSuggestionDetails(resource, position, this.suggestion); + } + + updateDetails(value: ISuggestion): void { + this.suggestion = assign(this.suggestion, value); } } @@ -425,7 +417,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable private shouldShowEmptySuggestionList: boolean; private suggestionSupportsAutoAccept: IKeybindingContextKey; private loadingTimeout: number; - private currentSuggestionDetails: TPromise; + private currentSuggestionDetails: TPromise; private focusedItem: CompletionItem; private completionModel: CompletionModel; @@ -534,6 +526,11 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable } private onListFocus(e: IFocusChangeEvent): void { + if (this.currentSuggestionDetails) { + this.currentSuggestionDetails.cancel(); + this.currentSuggestionDetails = null; + } + if (!e.elements.length) { return; } @@ -546,26 +543,24 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable const index = e.indexes[0]; - this.resolveDetails(item, index); - this.suggestionSupportsAutoAccept.set(!(item).suggestion.noAutoAccept); - - if (this.focusedItem) { - const index = this.completionModel.items.indexOf(this.focusedItem); - if (index > -1) this.list.splice(index, 1, this.focusedItem); - this.focusedItem = null; - } - - if (item) { - this.focusedItem = item; - this.list.splice(index, 1, item); - this.list.setFocus(index); - } - + this.suggestionSupportsAutoAccept.set(item.suggestion.noAutoAccept); + this.focusedItem = item; + this.list.setFocus(index); this.updateWidgetHeight(); + this.list.reveal(index); - if (item) { - this.list.reveal(index); - } + const resource = this.editor.getModel().getAssociatedResource(); + const position = this.model.getRequestPosition() || this.editor.getPosition(); + + this.currentSuggestionDetails = item.resolveDetails(resource, position) + .then(details => { + item.updateDetails(details); + this.list.setFocus(index); + this.updateWidgetHeight(); + this.list.reveal(index); + }) + .then(null, err => !isPromiseCanceledError(err) && onUnexpectedError(err)) + .then(() => this.currentSuggestionDetails = null); } private onModelModeChanged(): void { @@ -741,29 +736,6 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable } } - private resolveDetails(item: CompletionItem, index: number): void { - if (this.currentSuggestionDetails) { - this.currentSuggestionDetails.cancel(); - } - - this.currentSuggestionDetails = item.resolveDetails( - this.editor.getModel().getAssociatedResource(), - this.model.getRequestPosition() || this.editor.getPosition() - ); - - this.currentSuggestionDetails.then(() => { - this.currentSuggestionDetails = undefined; - - if (item === this.focusedItem) { - this.list.splice(index, 1, item); - this.list.setFocus(index); - this.updateWidgetHeight(); - } - }, - err => !isPromiseCanceledError(err) && onUnexpectedError(err) - ); - } - public selectNextPage(): boolean { switch (this.state) { case State.Hidden: -- GitLab