提交 7272e29f 编写于 作者: B Benjamin Pasero

quick access - restore matching as it was before for editor history entries

上级 461c563f
......@@ -308,22 +308,35 @@ export type QuickPickInput<T = IQuickPickItem> = T | IQuickPickSeparator;
export type IQuickPickItemWithResource = IQuickPickItem & { resource: URI | undefined };
export const quickPickItemScorerAccessor = new class implements IItemAccessor<IQuickPickItemWithResource> {
export class QuickPickItemScorerAccessor implements IItemAccessor<IQuickPickItemWithResource> {
constructor(private options?: { skipDescription?: boolean, skipPath?: boolean }) { }
getItemLabel(entry: IQuickPickItemWithResource): string {
return entry.label;
}
getItemDescription(entry: IQuickPickItemWithResource): string | undefined {
if (this.options?.skipDescription) {
return undefined;
}
return entry.description;
}
getItemPath(entry: IQuickPickItemWithResource): string | undefined {
if (this.options?.skipPath) {
return undefined;
}
if (entry.resource?.scheme === Schemas.file) {
return entry.resource.fsPath;
}
return entry.resource?.path;
}
};
}
export const quickPickItemScorerAccessor = new QuickPickItemScorerAccessor();
//#endregion
......@@ -4,7 +4,7 @@
*--------------------------------------------------------------------------------------------*/
import 'vs/css!./media/anythingQuickAccess';
import { IQuickPickSeparator, IQuickInputButton, IKeyMods, quickPickItemScorerAccessor } from 'vs/platform/quickinput/common/quickInput';
import { IQuickPickSeparator, IQuickInputButton, IKeyMods, quickPickItemScorerAccessor, QuickPickItemScorerAccessor } from 'vs/platform/quickinput/common/quickInput';
import { IPickerQuickAccessItem, PickerQuickAccessProvider, TriggerAction, FastAndSlowPicksType } from 'vs/platform/quickinput/browser/pickerQuickAccess';
import { prepareQuery, IPreparedQuery, compareItemsByScore, scoreItem } from 'vs/base/common/fuzzyScorer';
import { IFileQueryBuilderOptions, QueryBuilder } from 'vs/workbench/contrib/search/common/queryBuilder';
......@@ -168,6 +168,8 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
//#region Editor History
private readonly labelOnlyEditorHistoryPickAccessor = new QuickPickItemScorerAccessor({ skipDescription: true });
protected getEditorHistoryPicks(query: IPreparedQuery, range: IRange | undefined): Array<IAnythingQuickPickItem> {
if (!this.configuration.includeHistory) {
return []; // disabled
......@@ -178,6 +180,9 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
return this.historyService.getHistory().map(editor => this.createAnythingPick(editor, range));
}
// Only match on label of the editor unless the search includes path separators
const editorHistoryScorerAccessor = query.containsPathSeparator ? quickPickItemScorerAccessor : this.labelOnlyEditorHistoryPickAccessor;
// Otherwise filter and sort by query
const editorHistoryPicks: Array<IAnythingQuickPickItem> = [];
const scorerCache = Object.create(null); // TODO should keep this for as long as the picker is opened (also check other pickers)
......@@ -189,7 +194,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
const editorHistoryPick = this.createAnythingPick(editor, range);
const { score, labelMatch, descriptionMatch } = scoreItem(editorHistoryPick, query, false, quickPickItemScorerAccessor, scorerCache);
const { score, labelMatch, descriptionMatch } = scoreItem(editorHistoryPick, query, false, editorHistoryScorerAccessor, scorerCache);
if (!score) {
continue; // exclude editors not matching query
}
......@@ -202,7 +207,7 @@ export class AnythingQuickAccessProvider extends PickerQuickAccessProvider<IAnyt
editorHistoryPicks.push(editorHistoryPick);
}
return editorHistoryPicks.sort((editorA, editorB) => compareItemsByScore(editorA, editorB, query, false, quickPickItemScorerAccessor, scorerCache, () => -1));
return editorHistoryPicks.sort((editorA, editorB) => compareItemsByScore(editorA, editorB, query, false, editorHistoryScorerAccessor, scorerCache, () => -1));
}
//#endregion
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册