@@ -23,6 +23,9 @@ import { KeybindingResolver } from 'vs/platform/keybinding/common/keybindingReso
2323export const KEYBINDING_ENTRY_TEMPLATE_ID = 'keybinding.entry.template' ;
2424export const KEYBINDING_HEADER_TEMPLATE_ID = 'keybinding.header.template' ;
2525
26+ const SOURCE_DEFAULT = localize ( 'default' , "Default" ) ;
27+ const SOURCE_USER = localize ( 'user' , "User" ) ;
28+
2629export 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 ( / @ s o u r c e : \s * ( u s e r | d e f a u l t ) / i. test ( searchValue ) ) {
98+ keybindingItems = this . filterBySource ( keybindingItems , searchValue ) ;
99+ searchValue = searchValue . replace ( / @ s o u r c e : \s * ( u s e r | d e f a u l t ) / 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 / ^ @ s o u r c e : / 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 ( / @ s o u r c e : \s * d e f a u l t / i. test ( searchValue ) ) {
112+ return keybindingItems . filter ( k => k . source === SOURCE_DEFAULT ) ;
113+ }
114+ if ( / @ s o u r c e : \s * u s e r / 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