@@ -90,14 +90,27 @@ export class KeybindingsEditorModel extends EditorModel {
9090
9191 public fetch ( searchValue : string , sortByPrecedence : boolean = false ) : IKeybindingItemEntry [ ] {
9292 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 ) ;
100+ }
101+ searchValue = searchValue . trim ( ) ;
102+ return this . fetchKeybindingItems ( sortByPrecedence ? this . _keybindingItemsSortedByPrecedence : this . _keybindingItems , searchValue , quoteAtFirstChar && quoteAtLastChar ) ;
103+ }
104+
105+ private fetchKeybindingItems ( keybindingItems : IKeybindingItem [ ] , searchValue : string , completeMatch : boolean ) : IKeybindingItemEntry [ ] {
106+ if ( ! searchValue ) {
107+ return keybindingItems . map ( keybindingItem => ( { id : KeybindingsEditorModel . getId ( keybindingItem ) , keybindingItem, templateId : KEYBINDING_ENTRY_TEMPLATE_ID } ) ) ;
108+ }
93109
94110 if ( this . isSourceFilterApplied ( searchValue ) ) {
95- searchValue = this . getSourceFilterValue ( searchValue ) ;
96- searchValue = this . parseSearchValue ( searchValue ) ;
97- return this . fetchKeybindingItemsBySource ( sortByPrecedence ? this . _keybindingItemsSortedByPrecedence : this . _keybindingItems , searchValue , this . quoteAtFirst ( searchValue ) && this . quoteAtLast ( searchValue ) ) ;
111+ return this . filterBySource ( keybindingItems , this . getSourceFilterValue ( searchValue ) , completeMatch ) ;
98112 }
99- searchValue = this . parseSearchValue ( searchValue ) ;
100- return this . fetchKeybindingItemsByText ( sortByPrecedence ? this . _keybindingItemsSortedByPrecedence : this . _keybindingItems , searchValue , this . quoteAtFirst ( searchValue ) && this . quoteAtLast ( searchValue ) ) ;
113+ return this . filterByText ( keybindingItems , searchValue , completeMatch ) ;
101114 }
102115
103116 private isSourceFilterApplied ( searchValue : string ) : boolean {
@@ -108,31 +121,7 @@ export class KeybindingsEditorModel extends EditorModel {
108121 return searchValue . split ( '@source:' ) [ 1 ] . trim ( ) || '' ;
109122 }
110123
111- private quoteAtFirst ( searchValue : string ) {
112- return searchValue . charAt ( 0 ) === '"' ;
113- }
114-
115- private quoteAtLast ( searchValue : string ) {
116- return searchValue . charAt ( searchValue . length - 1 ) === '"' ;
117- }
118-
119- private parseSearchValue ( searchValue : string ) {
120- const quoteAtFirstChar = this . quoteAtFirst ( searchValue ) ;
121- const quoteAtLastChar = this . quoteAtLast ( searchValue ) ;
122- if ( quoteAtFirstChar ) {
123- searchValue = searchValue . substring ( 1 ) ;
124- }
125- if ( quoteAtLastChar ) {
126- searchValue = searchValue . substring ( 0 , searchValue . length - 1 ) ;
127- }
128- return searchValue . trim ( ) ;
129- }
130-
131- private fetchKeybindingItemsBySource ( keybindingItems : IKeybindingItem [ ] , searchValue : string , completeMatch : boolean ) : IKeybindingItemEntry [ ] {
132- if ( ! searchValue ) {
133- return keybindingItems . map ( keybindingItem => ( { id : KeybindingsEditorModel . getId ( keybindingItem ) , keybindingItem, templateId : KEYBINDING_ENTRY_TEMPLATE_ID } ) ) ;
134- }
135-
124+ private filterBySource ( keybindingItems : IKeybindingItem [ ] , searchValue : string , completeMatch : boolean ) : IKeybindingItemEntry [ ] {
136125 const result : IKeybindingItemEntry [ ] = [ ] ;
137126 const words = searchValue . split ( ' ' ) ;
138127 const keybindingWords = this . splitKeybindingWords ( words ) ;
@@ -155,11 +144,7 @@ export class KeybindingsEditorModel extends EditorModel {
155144 return result ;
156145 }
157146
158- private fetchKeybindingItemsByText ( keybindingItems : IKeybindingItem [ ] , searchValue : string , completeMatch : boolean ) : IKeybindingItemEntry [ ] {
159- if ( ! searchValue ) {
160- return keybindingItems . map ( keybindingItem => ( { id : KeybindingsEditorModel . getId ( keybindingItem ) , keybindingItem, templateId : KEYBINDING_ENTRY_TEMPLATE_ID } ) ) ;
161- }
162-
147+ private filterByText ( keybindingItems : IKeybindingItem [ ] , searchValue : string , completeMatch : boolean ) : IKeybindingItemEntry [ ] {
163148 const result : IKeybindingItemEntry [ ] = [ ] ;
164149 const words = searchValue . split ( ' ' ) ;
165150 const keybindingWords = this . splitKeybindingWords ( words ) ;
0 commit comments