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

Polish #43037

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