提交 2461331b 编写于 作者: J Joao Moreno

suggest: fix details issue

上级 4581ae3b
......@@ -218,7 +218,7 @@ export class List<T> 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<T> 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<T> 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<T> 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 {
......
......@@ -64,8 +64,6 @@ class CompletionItem {
support: ISuggestSupport;
container: ISuggestResult;
private _resolveDetails: TPromise<CompletionItem>;
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<CompletionItem> {
if (this._resolveDetails) {
return this._resolveDetails;
}
resolveDetails(resource: URI, position: EditorCommon.IPosition): TPromise<ISuggestion> {
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<boolean>;
private loadingTimeout: number;
private currentSuggestionDetails: TPromise<CompletionItem>;
private currentSuggestionDetails: TPromise<void>;
private focusedItem: CompletionItem;
private completionModel: CompletionModel;
......@@ -534,6 +526,11 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
}
private onListFocus(e: IFocusChangeEvent<CompletionItem>): 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(!(<CompletionItem>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:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册