提交 b64faa99 编写于 作者: S Sandeep Somavarapu

Polish #43037

上级 a716373a
...@@ -184,7 +184,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor ...@@ -184,7 +184,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
enabled: true, enabled: true,
id: KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS, id: KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS,
run: (): TPromise<any> => { run: (): TPromise<any> => {
this.searchWidget.setValue('@source: default'); this.searchWidget.setValue('@source:default');
return TPromise.as(null); return TPromise.as(null);
} }
}, },
...@@ -193,7 +193,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor ...@@ -193,7 +193,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
enabled: true, enabled: true,
id: KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS, id: KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS,
run: (): TPromise<any> => { run: (): TPromise<any> => {
this.searchWidget.setValue('@source: user'); this.searchWidget.setValue('@source:user');
return TPromise.as(null); return TPromise.as(null);
} }
} }
......
...@@ -23,6 +23,9 @@ import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingReso ...@@ -23,6 +23,9 @@ import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingReso
export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template'; export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template';
export const KEYBINDING_HEADER_TEMPLATE_ID = 'keybinding.header.template'; export const KEYBINDING_HEADER_TEMPLATE_ID = 'keybinding.header.template';
const SOURCE_DEFAULT = localize('default', "Default");
const SOURCE_USER = localize('user', "User");
export interface KeybindingMatch { export interface KeybindingMatch {
ctrlKey?: boolean; ctrlKey?: boolean;
shiftKey?: boolean; shiftKey?: boolean;
...@@ -89,55 +92,43 @@ export class KeybindingsEditorModel extends EditorModel { ...@@ -89,55 +92,43 @@ export class KeybindingsEditorModel extends EditorModel {
} }
public fetch(searchValue: string, sortByPrecedence: boolean = false): IKeybindingItemEntry[] { public fetch(searchValue: string, sortByPrecedence: boolean = false): IKeybindingItemEntry[] {
searchValue = searchValue.trim(); let keybindingItems = sortByPrecedence ? this._keybindingItemsSortedByPrecedence : this._keybindingItems;
const quoteAtFirstChar = searchValue.charAt(0) === '"';
const quoteAtLastChar = searchValue.charAt(searchValue.length - 1) === '"'; if (/@source:\s*(user|default)/i.test(searchValue)) {
if (quoteAtFirstChar) { keybindingItems = this.filterBySource(keybindingItems, searchValue);
searchValue = searchValue.substring(1); searchValue = searchValue.replace(/@source:\s*(user|default)/i, '');
}
if (quoteAtLastChar) {
searchValue = searchValue.substring(0, searchValue.length - 1);
} }
searchValue = searchValue.trim();
return this.fetchKeybindingItems(sortByPrecedence ? this._keybindingItemsSortedByPrecedence : this._keybindingItems, searchValue, quoteAtFirstChar && quoteAtLastChar);
}
private fetchKeybindingItems(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] { searchValue = searchValue.trim();
if (!searchValue) { if (!searchValue) {
return keybindingItems.map(keybindingItem => ({ id: KeybindingsEditorModel.getId(keybindingItem), keybindingItem, templateId: KEYBINDING_ENTRY_TEMPLATE_ID })); return keybindingItems.map(keybindingItem => ({ id: KeybindingsEditorModel.getId(keybindingItem), keybindingItem, templateId: KEYBINDING_ENTRY_TEMPLATE_ID }));
} }
if (this.isSourceFilterApplied(searchValue)) { return this.filterByText(keybindingItems, searchValue);
return this.filterBySource(keybindingItems, this.getSourceFilterValue(searchValue), completeMatch);
}
return this.filterByText(keybindingItems, searchValue, completeMatch);
}
private isSourceFilterApplied(searchValue: string): boolean {
return /^@source:/i.test(searchValue);
}
private getSourceFilterValue(searchValue: string): string {
return searchValue.split('@source:')[1].trim() || '';
} }
private matchSource(itemSource: string, searchValue: string): boolean { private filterBySource(keybindingItems: IKeybindingItem[], searchValue: string): IKeybindingItem[] {
return itemSource.toLowerCase() === searchValue.toLowerCase(); if (/@source:\s*default/i.test(searchValue)) {
return keybindingItems.filter(k => k.source === SOURCE_DEFAULT);
}
if (/@source:\s*user/i.test(searchValue)) {
return keybindingItems.filter(k => k.source === SOURCE_USER);
}
return keybindingItems;
} }
private filterBySource(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] { private filterByText(keybindingItems: IKeybindingItem[], searchValue: string): IKeybindingItemEntry[] {
return <IKeybindingItemEntry[]>keybindingItems const quoteAtFirstChar = searchValue.charAt(0) === '"';
.filter((keybindingItem: IKeybindingItem) => this.matchSource(keybindingItem.source, searchValue)) const quoteAtLastChar = searchValue.charAt(searchValue.length - 1) === '"';
.map((keybindingItem: IKeybindingItem) => ( const completeMatch = quoteAtFirstChar && quoteAtLastChar;
{ if (quoteAtFirstChar) {
id: KeybindingsEditorModel.getId(keybindingItem), searchValue = searchValue.substring(1);
templateId: KEYBINDING_ENTRY_TEMPLATE_ID, }
keybindingItem, if (quoteAtLastChar) {
} searchValue = searchValue.substring(0, searchValue.length - 1);
)); }
} searchValue = searchValue.trim();
private filterByText(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] {
const result: IKeybindingItemEntry[] = []; const result: IKeybindingItemEntry[] = [];
const words = searchValue.split(' '); const words = searchValue.split(' ');
const keybindingWords = this.splitKeybindingWords(words); const keybindingWords = this.splitKeybindingWords(words);
...@@ -235,7 +226,7 @@ export class KeybindingsEditorModel extends EditorModel { ...@@ -235,7 +226,7 @@ export class KeybindingsEditorModel extends EditorModel {
commandLabel: KeybindingsEditorModel.getCommandLabel(menuCommand, editorActionLabel), commandLabel: KeybindingsEditorModel.getCommandLabel(menuCommand, editorActionLabel),
commandDefaultLabel: KeybindingsEditorModel.getCommandDefaultLabel(menuCommand, workbenchActionsRegistry), commandDefaultLabel: KeybindingsEditorModel.getCommandDefaultLabel(menuCommand, workbenchActionsRegistry),
when: keybindingItem.when ? keybindingItem.when.serialize() : '', when: keybindingItem.when ? keybindingItem.when.serialize() : '',
source: keybindingItem.isDefault ? localize('default', "Default") : localize('user', "User") source: keybindingItem.isDefault ? SOURCE_DEFAULT : SOURCE_USER
}; };
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册