Allow to filter keyBindings by 'Source'.#43393
Conversation
|
@shobhitchittora Changes look good. To discover this feature, How about having a context menu with |
|
@sandy081 Why is the test failing in CI for windows ( About this -
Observation - Currently in Keyboard Shortcuts Tab, when you click on keybindings.json, it open up two tabs - one is Clarification - on firing action from the context menu ( |
|
@sandy081 Any comments on this ? 😇 |
|
@shobhitchittora I think we can provide these as secondary actions to the keybindings editor which will be shown as follows: This can be done by implementing Let me know if you need any help |
|
@sandy081 Thanks! This looks good. So on clicking on any of these actions, the corresponding filter is applied ? |
|
Also more questions -
|
|
@shobhitchittora You just have to implement |
Usage -> 'source: user' or 'source: default' Closes: microsoft#43037
7bfcf57 to
b31e4ab
Compare
1. Adds action constants in preferences.ts 2. Adds showUser and showDefault keybindings actions 3. Adds getSecondaryActions to register context menu actions
|
@sandy081 I've added secondary actions and pushed tests too. Please have a look. PS: Apologies for the delay. Was busy with work. 😇 |
|
Ping @sandy081 |
|
@shobhitchittora Provided some feedback otherwise it looks good. I guess, we can push this PR once requested changes are handled. Thanks |
|
@sandy081 I don't see any comments here. |
| private keybindingFocusContextKey: IContextKey<boolean>; | ||
| private searchFocusContextKey: IContextKey<boolean>; | ||
| private sortByPrecedence: Checkbox; | ||
| private secondaryActions: IAction[]; |
| return focusedElement && focusedElement.templateId === KEYBINDING_ENTRY_TEMPLATE_ID ? <IKeybindingItemEntry>focusedElement : null; | ||
| } | ||
|
|
||
| setKeybindingSource(searchString: string): TPromise<any> { |
| return TPromise.as(null); | ||
| } | ||
|
|
||
| showDefaultKeyBindings(): IAction { |
| }; | ||
| } | ||
|
|
||
| showUserKeyBindings(): IAction { |
There was a problem hiding this comment.
Done for both actions.
| } | ||
|
|
||
| getSecondaryActions(): IAction[] { | ||
| if (!this.secondaryActions) { |
There was a problem hiding this comment.
storing in secondaryActions is not necessary. Its ok to create the array and return
| this.keybindingMatches = keybindingItem.keybinding ? this.matchesKeybinding(keybindingItem.keybinding, searchValue, keybindingWords) : null; | ||
| } | ||
|
|
||
| private checkForSourceFilter(searchValue: string) { |
There was a problem hiding this comment.
What happens if the label of a command matches source: default? I would parse the search string here and return results based on the parsed value. If it is a source type filter then return corresponding entries otherwise do the existing filtering.
| label: localize('showDefaultKeybindings', "Show Default Keybindings"), | ||
| enabled: true, | ||
| id: KEYBINDINGS_EDITOR_SHOW_DEFAULT_KEYBINDINGS, | ||
| run: () => this.setKeybindingSource('source: default') |
There was a problem hiding this comment.
I would use following format:
@source: default
This is consistent with filtering in Extensions viewlet
There was a problem hiding this comment.
Changed to use @source:
|
@shobhitchittora Sorry forgot to submit |
…itchittora/vscode into keyBindingsEditor-filter-by-source
| sourceMatches: keybindingMatches.sourceMatches, | ||
| whenMatches: keybindingMatches.whenMatches | ||
| }); | ||
| if (sourceFilterApplied) { |
There was a problem hiding this comment.
- Is there a better way to push results based on whether
@sourcefilter is applied or not? - Can we move refactor it into on method which checks for respective matches and another one which creates the final
resultarray?
There was a problem hiding this comment.
@shobhitchittora You can have two methods one for filtering based on source and the other does full text search and call either of them by checking the search text. It can look something like follows
if (/@source:/i.test(searchValue)) {
return this.filterBySource(searchValue);
}
return this.filterByText(searchValue);| return keybindingItems.map(keybindingItem => ({ id: KeybindingsEditorModel.getId(keybindingItem), keybindingItem, templateId: KEYBINDING_ENTRY_TEMPLATE_ID })); | ||
| } | ||
|
|
||
| const result: IKeybindingItemEntry[] = []; |
There was a problem hiding this comment.
Not sure if you need this code any more because this is handled by fetchKeybindingItemsByText
There was a problem hiding this comment.
fetchKeybindingItemsByText is called conditionally when no @source: filter is applied.
Otherwise fetchKeybindingItemsBySource will be called.
| if (this.isSourceFilterApplied(searchValue)) { | ||
| searchValue = this.getSourceFilterValue(searchValue); | ||
| searchValue = this.parseSearchValue(searchValue); | ||
| return this.fetchKeybindingItemsBySource(sortByPrecedence ? this._keybindingItemsSortedByPrecedence : this._keybindingItems, searchValue, this.quoteAtFirst(searchValue) && this.quoteAtLast(searchValue)); |
There was a problem hiding this comment.
Not sure why you need compute quotes here?
There was a problem hiding this comment.
For the same reasons as above.
|
|
||
| if (this.isSourceFilterApplied(searchValue)) { | ||
| searchValue = this.getSourceFilterValue(searchValue); | ||
| searchValue = this.parseSearchValue(searchValue); |
There was a problem hiding this comment.
Why do we need to parseSearchValue?
There was a problem hiding this comment.
This is added to handle the case with quotes and source filter is applied. --> @source: "user" / @source: "default"
There was a problem hiding this comment.
@shobhitchittora Lets make it simple and support only @source:user or @source:default. I do not think why we need to support quotes. This will make everything much simpler
There was a problem hiding this comment.
Yeah I probably over-complicated it, because I saw quotes were also supported. Will simplify it. 💪🏼
| } | ||
|
|
||
| private filterBySource(keybindingItems: IKeybindingItem[], searchValue: string, completeMatch: boolean): IKeybindingItemEntry[] { | ||
| const result: IKeybindingItemEntry[] = []; |
There was a problem hiding this comment.
@shobhitchittora I think we are very good with the changes except for changing filterBySource method a bit. Instead of delegating the filtering to KeybindingItemMatches lets filter keybindingItems by source directly and map them filtered results to IKeybindingItemEntry.
Sorry for providing more comments :(
There was a problem hiding this comment.
@sandy081 Don't be sorry. I encourage comments / suggestions till it's the best. 😇
|
@shobhitchittora Thanks for the PR. Merged. |

This adds a source filter to the Key Bindings Editor View.
Usage:
source: user|source: defaultTasks -
Closes: #43037