提交 10ead5ff 编写于 作者: J Joao Moreno

suggest: next, previous

上级 6b495479
...@@ -109,6 +109,18 @@ class Trait implements IDisposable { ...@@ -109,6 +109,18 @@ class Trait implements IDisposable {
return this.indexes.some(i => i === index); return this.indexes.some(i => i === index);
} }
next(n: number): void {
let index = this.indexes.length ? this.indexes[0] : 0;
index = Math.min(index + n, this.indexes.length);
this.set(index);
}
previous(n: number): void {
let index = this.indexes.length ? this.indexes[0] : this.indexes.length - 1;
index = Math.max(index - n, 0);
this.set(index);
}
wrapRenderer<T, D>(renderer: IRenderer<T, D>): IRenderer<T, ITraitTemplateData<D>> { wrapRenderer<T, D>(renderer: IRenderer<T, D>): IRenderer<T, ITraitTemplateData<D>> {
return new TraitRenderer<T, D>(this, renderer); return new TraitRenderer<T, D>(this, renderer);
} }
...@@ -202,11 +214,41 @@ export class List<T> implements IDisposable { ...@@ -202,11 +214,41 @@ export class List<T> implements IDisposable {
indexes.forEach(i => this.view.splice(i, 1, this.view.element(i))); indexes.forEach(i => this.view.splice(i, 1, this.view.element(i)));
} }
selectNext(n = 1, loop = false): void {
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));
}
selectPrevious(n = 1, loop = false): void {
if (this.length === 0) return;
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));
}
setFocus(...indexes: number[]): void { setFocus(...indexes: number[]): void {
indexes = indexes.concat(this.focus.set(...indexes)); indexes = indexes.concat(this.focus.set(...indexes));
indexes.forEach(i => this.view.splice(i, 1, this.view.element(i))); indexes.forEach(i => this.view.splice(i, 1, this.view.element(i)));
} }
focusNext(n = 1, loop = false): void {
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));
}
focusPrevious(n = 1, loop = false): void {
if (this.length === 0) return;
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));
}
getFocus(): T[] { getFocus(): T[] {
return this.focus.get().map(i => this.view.element(i)); return this.focus.get().map(i => this.view.element(i));
} }
......
...@@ -426,7 +426,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -426,7 +426,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
private suggestionSupportsAutoAccept: IKeybindingContextKey<boolean>; private suggestionSupportsAutoAccept: IKeybindingContextKey<boolean>;
private loadingTimeout: number; private loadingTimeout: number;
private currentSuggestionDetails: TPromise<CompletionItem>; private currentSuggestionDetails: TPromise<CompletionItem>;
private oldFocus: CompletionItem; private focusedItem: CompletionItem;
private completionModel: CompletionModel; private completionModel: CompletionModel;
private telemetryData: ITelemetryData; private telemetryData: ITelemetryData;
...@@ -453,7 +453,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -453,7 +453,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
@IInstantiationService instantiationService: IInstantiationService @IInstantiationService instantiationService: IInstantiationService
) { ) {
this.isAuto = false; this.isAuto = false;
this.oldFocus = null; this.focusedItem = null;
this.suggestionSupportsAutoAccept = keybindingService.createKey(CONTEXT_SUGGESTION_SUPPORTS_ACCEPT_ON_KEY, true); this.suggestionSupportsAutoAccept = keybindingService.createKey(CONTEXT_SUGGESTION_SUPPORTS_ACCEPT_ON_KEY, true);
this.telemetryData = null; this.telemetryData = null;
...@@ -484,7 +484,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -484,7 +484,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
SuggestRegistry.onDidChange(() => this.onModelModeChanged()), SuggestRegistry.onDidChange(() => this.onModelModeChanged()),
// editor.addListener2(EditorCommon.EventType.EditorTextBlur, () => this.onEditorBlur()), // editor.addListener2(EditorCommon.EventType.EditorTextBlur, () => this.onEditorBlur()),
this.list.onSelectionChange(e => this.onListSelection(e)), this.list.onSelectionChange(e => this.onListSelection(e)),
// this.list.addListener2('focus', e => this.onTreeFocus(e)), this.list.onFocusChange(e => this.onListFocus(e)),
this.editor.addListener2(EditorCommon.EventType.CursorSelectionChanged, () => this.onCursorSelectionChanged()), this.editor.addListener2(EditorCommon.EventType.CursorSelectionChanged, () => this.onCursorSelectionChanged()),
this.model.onDidTrigger(e => this.onDidTrigger(e)), this.model.onDidTrigger(e => this.onDidTrigger(e)),
this.model.onDidSuggest(e => this.onDidSuggest(e)), this.model.onDidSuggest(e => this.onDidSuggest(e)),
...@@ -533,35 +533,47 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -533,35 +533,47 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
}, 0); }, 0);
} }
// private onTreeFocus(e: Tree.IFocusEvent): void { private onListFocus(e: IFocusChangeEvent<CompletionItem>): void {
// const focus = e.focus; if (!e.elements.length) {
// const payload = e.payload; return;
}
// if (focus instanceof CompletionItem) { const item = e.elements[0];
// this.resolveDetails(<CompletionItem>focus);
// this.suggestionSupportsAutoAccept.set(!(<CompletionItem>focus).suggestion.noAutoAccept);
// }
// const elementsToRefresh: any[] = []; if (item === this.focusedItem) {
return;
}
// if (this.oldFocus) { const index = e.indexes[0];
// elementsToRefresh.push(this.oldFocus); // const payload = e.payload;
// }
// if (focus) { this.resolveDetails(item, index);
// elementsToRefresh.push(focus); this.suggestionSupportsAutoAccept.set(!(<CompletionItem>item).suggestion.noAutoAccept);
// }
// this.oldFocus = focus; if (this.focusedItem) {
const index = this.completionModel.items.indexOf(this.focusedItem);
if (index > -1) this.list.splice(index, 1, this.focusedItem);
this.focusedItem = null;
}
// this.list.refreshAll(elementsToRefresh).done(() => { if (item) {
// this.updateWidgetHeight(); this.focusedItem = item;
this.list.splice(index, 1, item);
this.list.setFocus(index);
}
// if (focus) { this.updateWidgetHeight();
// return this.list.reveal(focus, (payload && payload.firstSuggestion) ? 0 : null);
// } if (item) {
// }, onUnexpectedError); this.list.reveal(index);
// } }
// this.list.refreshAll(elementsToRefresh).done(() => {
// if (item) {
// return this.list.reveal(item, (payload && payload.firstSuggestion) ? 0 : null);
// }
// }, onUnexpectedError);
}
private onModelModeChanged(): void { private onModelModeChanged(): void {
const model = this.editor.getModel(); const model = this.editor.getModel();
...@@ -737,26 +749,28 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -737,26 +749,28 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
} }
} }
// private resolveDetails(item: CompletionItem): void { private resolveDetails(item: CompletionItem, index: number): void {
// if (!item) { if (this.currentSuggestionDetails) {
// return; this.currentSuggestionDetails.cancel();
// } }
// if (this.currentSuggestionDetails) { this.currentSuggestionDetails = item.resolveDetails(
// this.currentSuggestionDetails.cancel(); this.editor.getModel().getAssociatedResource(),
// } this.model.getRequestPosition() || this.editor.getPosition()
);
// this.currentSuggestionDetails = item.resolveDetails( this.currentSuggestionDetails.then(() => {
// this.editor.getModel().getAssociatedResource(), this.currentSuggestionDetails = undefined;
// this.model.getRequestPosition() || this.editor.getPosition()
// );
// this.currentSuggestionDetails.then(() => { if (item === this.focusedItem) {
// this.currentSuggestionDetails = undefined; this.list.splice(index, 1, item);
// return this.list.refresh(item).then(() => this.updateWidgetHeight()); this.list.setFocus(index);
// }) this.updateWidgetHeight();
// .done(null, err => !isPromiseCanceledError(err) && onUnexpectedError(err)); }
// } },
err => !isPromiseCanceledError(err) && onUnexpectedError(err)
);
}
public selectNextPage(): boolean { public selectNextPage(): boolean {
return false; return false;
...@@ -775,23 +789,18 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -775,23 +789,18 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
} }
public selectNext(): boolean { public selectNext(): boolean {
return false; switch (this.state) {
// switch (this.state) { case State.Hidden:
// case State.Hidden: return false;
// return false; case State.Details:
// case State.Details: this.details.scrollDown();
// this.details.scrollDown(); return true;
// return true; case State.Loading:
// case State.Loading: return !this.isAuto;
// return !this.isAuto; default:
// default: this.list.focusNext(1, true);
// const focus = this.list.getFocus(); return true;
// this.list.focusNext(1); }
// if (focus === this.list.getFocus()) {
// this.list.focusFirst();
// }
// return true;
// }
} }
public selectPreviousPage(): boolean { public selectPreviousPage(): boolean {
...@@ -811,23 +820,18 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -811,23 +820,18 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
} }
public selectPrevious(): boolean { public selectPrevious(): boolean {
return false; switch (this.state) {
// switch (this.state) { case State.Hidden:
// case State.Hidden: return false;
// return false; case State.Details:
// case State.Details: this.details.scrollUp();
// this.details.scrollUp(); return true;
// return true; case State.Loading:
// case State.Loading: return !this.isAuto;
// return !this.isAuto; default:
// default: this.list.focusPrevious(1, true);
// const focus = this.list.getFocus(); return true;
// this.list.focusPrevious(1); }
// if (focus === this.list.getFocus()) {
// this.list.focusLast();
// }
// return true;
// }
} }
public acceptSelectedSuggestion(): boolean { public acceptSelectedSuggestion(): boolean {
...@@ -951,7 +955,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable ...@@ -951,7 +955,7 @@ export class SuggestWidget implements EditorBrowser.IContentWidget, IDisposable
this.state = null; this.state = null;
this.suggestionSupportsAutoAccept = null; this.suggestionSupportsAutoAccept = null;
this.currentSuggestionDetails = null; this.currentSuggestionDetails = null;
this.oldFocus = null; this.focusedItem = null;
this.telemetryData = null; this.telemetryData = null;
this.telemetryService = null; this.telemetryService = null;
this.telemetryTimer = null; this.telemetryTimer = null;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册