Skip to content

Commit

Permalink
Search relevance in Quick Pick control (fixes #18003)
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Jan 4, 2017
1 parent ada971a commit 8b834d0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
10 changes: 5 additions & 5 deletions src/vs/base/parts/quickopen/browser/quickOpenModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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);
}
}
18 changes: 16 additions & 2 deletions src/vs/workbench/browser/parts/quickopen/quickOpenController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand All @@ -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) : []
Expand Down
8 changes: 4 additions & 4 deletions src/vs/workbench/parts/quickopen/browser/gotoSymbolHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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) => {
Expand Down

0 comments on commit 8b834d0

Please sign in to comment.