提交 8b834d0f 编写于 作者: B Benjamin Pasero

Search relevance in Quick Pick control (fixes #18003)

上级 ada971a4
......@@ -689,15 +689,15 @@ export class QuickOpenModel implements
return this._entries;
}
getId(entry: QuickOpenEntry): string {
public getId(entry: QuickOpenEntry): string {
return entry.getId();
}
getLabel(entry: QuickOpenEntry): string {
public getLabel(entry: QuickOpenEntry): string {
return entry.getLabel();
}
getAriaLabel(entry: QuickOpenEntry): string {
public getAriaLabel(entry: QuickOpenEntry): string {
const ariaLabel = entry.getAriaLabel();
if (ariaLabel) {
return nls.localize('quickOpenAriaLabelEntry', "{0}, picker", entry.getAriaLabel());
......@@ -706,11 +706,11 @@ export class QuickOpenModel implements
return nls.localize('quickOpenAriaLabel', "picker");
}
isVisible(entry: QuickOpenEntry): boolean {
public isVisible(entry: QuickOpenEntry): boolean {
return !entry.isHidden();
}
run(entry: QuickOpenEntry, mode: Mode, context: IContext): boolean {
public run(entry: QuickOpenEntry, mode: Mode, context: IContext): boolean {
return entry.run(mode, context);
}
}
......@@ -342,9 +342,9 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
// Model
const model = new QuickOpenModel();
const entries = picks.map(e => this.instantiationService.createInstance(PickOpenEntry, e, () => progress(e)));
const entries = picks.map((e, index) => this.instantiationService.createInstance(PickOpenEntry, e, index, () => progress(e)));
if (picks.length === 0) {
entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, null));
entries.push(this.instantiationService.createInstance(PickOpenEntry, { label: nls.localize('emptyPicks', "There are no entries to pick from") }, 0, null));
}
model.setEntries(entries);
......@@ -414,6 +414,15 @@ export class QuickOpenController extends WorkbenchComponent implements IQuickOpe
});
}
// Sort by value
model.entries.sort((pickA: PickOpenEntry, pickB: PickOpenEntry) => {
if (!value) {
return pickA.index - pickB.index; // restore natural order
}
return QuickOpenEntry.compare(pickA, pickB, value);
});
this.pickOpenWidget.refresh(model, value ? { autoFocusFirstEntry: true } : autoFocus);
},
onShow: () => this.handleOnShow(true),
......@@ -1001,6 +1010,7 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
constructor(
item: IPickOpenEntry,
private _index: number,
private onPreview: () => void,
@IModeService private modeService: IModeService,
@IModelService private modelService: IModelService
......@@ -1018,6 +1028,10 @@ class PickOpenEntry extends PlaceholderQuickOpenEntry {
this.isFolder = fileItem.isFolder;
}
public get index(): number {
return this._index;
}
public getLabelOptions(): IIconLabelOptions {
return {
extraClasses: this.resource ? getIconClasses(this.modelService, this.modeService, this.resource, this.isFolder) : []
......
......@@ -46,7 +46,7 @@ class OutlineModel extends QuickOpenModel {
this.outline = outline;
}
public dofilter(searchValue: string): void {
public applyFilter(searchValue: string): void {
// Normalize search
let normalizedSearchValue = searchValue;
......@@ -389,10 +389,10 @@ export class GotoSymbolHandler extends QuickOpenHandler {
}
// Resolve Outline Model
return this.getActiveOutline().then((outline) => {
return this.getActiveOutline().then(outline => {
// Filter by search
outline.dofilter(searchValue);
outline.applyFilter(searchValue);
return outline;
});
......@@ -548,7 +548,7 @@ export class GotoSymbolHandler extends QuickOpenHandler {
public clearDecorations(): void {
if (this.rangeHighlightDecorationId) {
this.editorService.getVisibleEditors().forEach((editor) => {
this.editorService.getVisibleEditors().forEach(editor => {
if (editor.position === this.rangeHighlightDecorationId.position) {
const editorControl = <IEditor>editor.getControl();
editorControl.changeDecorations((changeAccessor: IModelDecorationsChangeAccessor) => {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册