Skip to content

Commit b64faa9

Browse files
committed
1 parent a716373 commit b64faa9

2 files changed

Lines changed: 32 additions & 41 deletions

File tree

src/vs/workbench/parts/preferences/browser/keybindingsEditor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
184184
enabled: true,
185185
id: KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS,
186186
run: (): TPromise<any> => {
187-
this.searchWidget.setValue('@source: default');
187+
this.searchWidget.setValue('@source:default');
188188
return TPromise.as(null);
189189
}
190190
},
@@ -193,7 +193,7 @@ export class KeybindingsEditor extends BaseEditor implements IKeybindingsEditor
193193
enabled: true,
194194
id: KEYBINDINGS_EDITOR_SHOW_USER_KEYBINDINGS,
195195
run: (): TPromise<any> => {
196-
this.searchWidget.setValue('@source: user');
196+
this.searchWidget.setValue('@source:user');
197197
return TPromise.as(null);
198198
}
199199
}

src/vs/workbench/parts/preferences/common/keybindingsEditorModel.ts

Lines changed: 30 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingReso
2323
export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template';
2424
export const KEYBINDING_HEADER_TEMPLATE_ID = 'keybinding.header.template';
2525

26+
const SOURCE_DEFAULT = localize('default', "Default");
27+
const SOURCE_USER = localize('user', "User");
28+
2629
export interface KeybindingMatch {
2730
ctrlKey?: boolean;
2831
shiftKey?: boolean;
@@ -89,55 +92,43 @@ export class KeybindingsEditorModel extends EditorModel {
8992
}
9093

9194
public fetch(searchValue: string, sortByPrecedence: boolean = false): IKeybindingItemEntry[] {
92-
searchValue = searchValue.trim();
93-
const quoteAtFirstChar = searchValue.charAt(0) === '"';
94-
const quoteAtLastChar = searchValue.charAt(searchValue.length - 1) === '"';
95-
if (quoteAtFirstChar) {
96-
searchValue = searchValue.substring(1);
97-
}
98-
if (quoteAtLastChar) {
99-
searchValue = searchValue.substring(0, searchValue.length - 1);
95+
let keybindingItems = sortByPrecedence ? this._keybindingItemsSortedByPrecedence : this._keybindingItems;
96+
97+
if (/@source:\s*(user|default)/i.test(searchValue)) {
98+
keybindingItems = this.filterBySource(keybindingItems, searchValue);
99+
searchValue = searchValue.replace(/@source:\s*(user|default)/i, '');
100100
}
101-
searchValue = searchValue.trim();
102-
return this.fetchKeybindingItems(sortByPrecedence ? this._keybindingItemsSortedByPrecedence : this._keybindingItems, searchValue, quoteAtFirstChar && quoteAtLastChar);
103-
}
104101

105-
private fetchKeybindingItems(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] {
102+
searchValue = searchValue.trim();
106103
if (!searchValue) {
107104
return keybindingItems.map(keybindingItem => ({ id: KeybindingsEditorModel.getId(keybindingItem), keybindingItem, templateId: KEYBINDING_ENTRY_TEMPLATE_ID }));
108105
}
109106

110-
if (this.isSourceFilterApplied(searchValue)) {
111-
return this.filterBySource(keybindingItems, this.getSourceFilterValue(searchValue), completeMatch);
112-
}
113-
return this.filterByText(keybindingItems, searchValue, completeMatch);
114-
}
115-
116-
private isSourceFilterApplied(searchValue: string): boolean {
117-
return /^@source:/i.test(searchValue);
118-
}
119-
120-
private getSourceFilterValue(searchValue: string): string {
121-
return searchValue.split('@source:')[1].trim() || '';
107+
return this.filterByText(keybindingItems, searchValue);
122108
}
123109

124-
private matchSource(itemSource: string, searchValue: string): boolean {
125-
return itemSource.toLowerCase() === searchValue.toLowerCase();
110+
private filterBySource(keybindingItems: IKeybindingItem[], searchValue: string): IKeybindingItem[] {
111+
if (/@source:\s*default/i.test(searchValue)) {
112+
return keybindingItems.filter(k => k.source === SOURCE_DEFAULT);
113+
}
114+
if (/@source:\s*user/i.test(searchValue)) {
115+
return keybindingItems.filter(k => k.source === SOURCE_USER);
116+
}
117+
return keybindingItems;
126118
}
127119

128-
private filterBySource(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] {
129-
return <IKeybindingItemEntry[]>keybindingItems
130-
.filter((keybindingItem: IKeybindingItem) => this.matchSource(keybindingItem.source, searchValue))
131-
.map((keybindingItem: IKeybindingItem) => (
132-
{
133-
id: KeybindingsEditorModel.getId(keybindingItem),
134-
templateId: KEYBINDING_ENTRY_TEMPLATE_ID,
135-
keybindingItem,
136-
}
137-
));
138-
}
120+
private filterByText(keybindingItems: IKeybindingItem[], searchValue: string): IKeybindingItemEntry[] {
121+
const quoteAtFirstChar = searchValue.charAt(0) === '"';
122+
const quoteAtLastChar = searchValue.charAt(searchValue.length - 1) === '"';
123+
const completeMatch = quoteAtFirstChar && quoteAtLastChar;
124+
if (quoteAtFirstChar) {
125+
searchValue = searchValue.substring(1);
126+
}
127+
if (quoteAtLastChar) {
128+
searchValue = searchValue.substring(0, searchValue.length - 1);
129+
}
130+
searchValue = searchValue.trim();
139131

140-
private filterByText(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] {
141132
const result: IKeybindingItemEntry[] = [];
142133
const words = searchValue.split(' ');
143134
const keybindingWords = this.splitKeybindingWords(words);
@@ -235,7 +226,7 @@ export class KeybindingsEditorModel extends EditorModel {
235226
commandLabel: KeybindingsEditorModel.getCommandLabel(menuCommand, editorActionLabel),
236227
commandDefaultLabel: KeybindingsEditorModel.getCommandDefaultLabel(menuCommand, workbenchActionsRegistry),
237228
when: keybindingItem.when ? keybindingItem.when.serialize() : '',
238-
source: keybindingItem.isDefault ? localize('default', "Default") : localize('user', "User")
229+
source: keybindingItem.isDefault ? SOURCE_DEFAULT : SOURCE_USER
239230
};
240231
}
241232

0 commit comments

Comments
 (0)