@@ -116,20 +116,23 @@ export class SearchWidget extends Widget {
116116 private _onReplaceAll = this . _register ( new Emitter < void > ( ) ) ;
117117 public readonly onReplaceAll : Event < void > = this . _onReplaceAll . event ;
118118
119+ private _onBlur = this . _register ( new Emitter < void > ( ) ) ;
120+ public readonly onBlur : Event < void > = this . _onBlur . event ;
121+
119122 constructor (
120123 container : Builder ,
121124 options : ISearchWidgetOptions ,
122125 @IContextViewService private contextViewService : IContextViewService ,
123126 @IThemeService private themeService : IThemeService ,
124- @IContextKeyService private keyBindingService : IContextKeyService ,
125- @IKeybindingService private keyBindingService2 : IKeybindingService ,
127+ @IContextKeyService private contextKeyService : IContextKeyService ,
128+ @IKeybindingService private keyBindingService : IKeybindingService ,
126129 @IClipboardService private clipboardServce : IClipboardService ,
127130 @IConfigurationService private configurationService : IConfigurationService
128131 ) {
129132 super ( ) ;
130- this . replaceActive = Constants . ReplaceActiveKey . bindTo ( this . keyBindingService ) ;
131- this . searchInputBoxFocused = Constants . SearchInputBoxFocusedKey . bindTo ( this . keyBindingService ) ;
132- this . replaceInputBoxFocused = Constants . ReplaceInputBoxFocusedKey . bindTo ( this . keyBindingService ) ;
133+ this . replaceActive = Constants . ReplaceActiveKey . bindTo ( this . contextKeyService ) ;
134+ this . searchInputBoxFocused = Constants . SearchInputBoxFocusedKey . bindTo ( this . contextKeyService ) ;
135+ this . replaceInputBoxFocused = Constants . ReplaceInputBoxFocusedKey . bindTo ( this . contextKeyService ) ;
133136 this . render ( container , options ) ;
134137 }
135138
@@ -164,6 +167,10 @@ export class SearchWidget extends Widget {
164167 return ! dom . hasClass ( this . replaceContainer , 'disabled' ) ;
165168 }
166169
170+ isReplaceActive ( ) : boolean {
171+ return this . replaceActive . get ( ) ;
172+ }
173+
167174 public getReplaceValue ( ) : string {
168175 return this . replaceInput . value ;
169176 }
@@ -210,6 +217,14 @@ export class SearchWidget extends Widget {
210217 return this . replaceInput . hasFocus ( ) ;
211218 }
212219
220+ public focusReplaceAllAction ( ) : void {
221+ this . replaceActionBar . focus ( true ) ;
222+ }
223+
224+ public focusRegexAction ( ) : void {
225+ this . searchInput . focusOnRegex ( ) ;
226+ }
227+
213228 private render ( container : Builder , options : ISearchWidgetOptions ) : void {
214229 this . domNode = container . div ( { 'class' : 'search-widget' } ) . style ( { position : 'relative' } ) . getHTMLElement ( ) ;
215230 this . renderToggleReplaceButton ( this . domNode ) ;
@@ -237,23 +252,25 @@ export class SearchWidget extends Widget {
237252 label : nls . localize ( 'label.Search' , 'Search: Type Search Term and press Enter to search or Escape to cancel' ) ,
238253 validation : ( value : string ) => this . validateSearchInput ( value ) ,
239254 placeholder : nls . localize ( 'search.placeHolder' , "Search" ) ,
240- appendCaseSensitiveLabel : appendKeyBindingLabel ( '' , this . keyBindingService2 . lookupKeybinding ( Constants . ToggleCaseSensitiveCommandId ) , this . keyBindingService2 ) ,
241- appendWholeWordsLabel : appendKeyBindingLabel ( '' , this . keyBindingService2 . lookupKeybinding ( Constants . ToggleWholeWordCommandId ) , this . keyBindingService2 ) ,
242- appendRegexLabel : appendKeyBindingLabel ( '' , this . keyBindingService2 . lookupKeybinding ( Constants . ToggleRegexCommandId ) , this . keyBindingService2 ) ,
255+ appendCaseSensitiveLabel : appendKeyBindingLabel ( '' , this . keyBindingService . lookupKeybinding ( Constants . ToggleCaseSensitiveCommandId ) , this . keyBindingService ) ,
256+ appendWholeWordsLabel : appendKeyBindingLabel ( '' , this . keyBindingService . lookupKeybinding ( Constants . ToggleWholeWordCommandId ) , this . keyBindingService ) ,
257+ appendRegexLabel : appendKeyBindingLabel ( '' , this . keyBindingService . lookupKeybinding ( Constants . ToggleRegexCommandId ) , this . keyBindingService ) ,
243258 history : options . searchHistory
244259 } ;
245260
246261 let searchInputContainer = dom . append ( parent , dom . $ ( '.search-container.input-box' ) ) ;
247- this . searchInput = this . _register ( new ContextScopedFindInput ( searchInputContainer , this . contextViewService , inputOptions , this . keyBindingService ) ) ;
262+ this . searchInput = this . _register ( new ContextScopedFindInput ( searchInputContainer , this . contextViewService , inputOptions , this . contextKeyService ) ) ;
248263 this . _register ( attachFindInputBoxStyler ( this . searchInput , this . themeService ) ) ;
249- this . searchInput . onKeyUp ( ( keyboardEvent : IKeyboardEvent ) => this . onSearchInputKeyUp ( keyboardEvent ) ) ;
264+ this . searchInput . onKeyDown ( ( keyboardEvent : IKeyboardEvent ) => this . onSearchInputKeyDown ( keyboardEvent ) ) ;
250265 this . searchInput . setValue ( options . value || '' ) ;
251266 this . searchInput . setRegex ( ! ! options . isRegex ) ;
252267 this . searchInput . setCaseSensitive ( ! ! options . isCaseSensitive ) ;
253268 this . searchInput . setWholeWords ( ! ! options . isWholeWords ) ;
254269 this . _register ( this . onSearchSubmit ( ( ) => {
255270 this . searchInput . inputBox . addToHistory ( this . searchInput . getValue ( ) ) ;
256271 } ) ) ;
272+ this . searchInput . onCaseSensitiveKeyDown ( ( keyboardEvent : IKeyboardEvent ) => this . onCaseSensitiveKeyDown ( keyboardEvent ) ) ;
273+ this . searchInput . onRegexKeyDown ( ( keyboardEvent : IKeyboardEvent ) => this . onRegexKeyDown ( keyboardEvent ) ) ;
257274
258275 this . _register ( this . onReplaceValueChanged ( ( ) => {
259276 this . replaceInput . addToHistory ( this . replaceInput . value ) ;
@@ -287,9 +304,9 @@ export class SearchWidget extends Widget {
287304 ariaLabel : nls . localize ( 'label.Replace' , 'Replace: Type replace term and press Enter to preview or Escape to cancel' ) ,
288305 placeholder : nls . localize ( 'search.replace.placeHolder' , "Replace" ) ,
289306 history : options . replaceHistory || [ ]
290- } , this . keyBindingService ) ) ;
307+ } , this . contextKeyService ) ) ;
291308 this . _register ( attachInputBoxStyler ( this . replaceInput , this . themeService ) ) ;
292- this . onkeyup ( this . replaceInput . inputElement , ( keyboardEvent ) => this . onReplaceInputKeyUp ( keyboardEvent ) ) ;
309+ this . onkeydown ( this . replaceInput . inputElement , ( keyboardEvent ) => this . onReplaceInputKeyDown ( keyboardEvent ) ) ;
293310 this . replaceInput . onDidChange ( ( ) => this . _onReplaceValueChanged . fire ( ) ) ;
294311 this . searchInput . inputBox . onDidChange ( ( ) => this . onSearchInputChanged ( ) ) ;
295312
@@ -320,15 +337,11 @@ export class SearchWidget extends Widget {
320337 public setReplaceAllActionState ( enabled : boolean ) : void {
321338 if ( this . replaceAllAction . enabled !== enabled ) {
322339 this . replaceAllAction . enabled = enabled ;
323- this . replaceAllAction . label = enabled ? SearchWidget . REPLACE_ALL_ENABLED_LABEL ( this . keyBindingService2 ) : SearchWidget . REPLACE_ALL_DISABLED_LABEL ;
340+ this . replaceAllAction . label = enabled ? SearchWidget . REPLACE_ALL_ENABLED_LABEL ( this . keyBindingService ) : SearchWidget . REPLACE_ALL_DISABLED_LABEL ;
324341 this . updateReplaceActiveState ( ) ;
325342 }
326343 }
327344
328- private isReplaceActive ( ) : boolean {
329- return this . replaceActive . get ( ) ;
330- }
331-
332345 private updateReplaceActiveState ( ) : void {
333346 let currentState = this . isReplaceActive ( ) ;
334347 let newState = this . isReplaceShown ( ) && this . replaceAllAction . enabled ;
@@ -366,26 +379,61 @@ export class SearchWidget extends Widget {
366379 this . setReplaceAllActionState ( false ) ;
367380 }
368381
369- private onSearchInputKeyUp ( keyboardEvent : IKeyboardEvent ) {
370- switch ( keyboardEvent . keyCode ) {
371- case KeyCode . Enter :
372- this . submitSearch ( ) ;
373- return ;
374- case KeyCode . Escape :
375- this . _onSearchCancel . fire ( ) ;
376- return ;
377- default :
378- return ;
382+ private onSearchInputKeyDown ( keyboardEvent : IKeyboardEvent ) {
383+ if ( keyboardEvent . equals ( KeyCode . Enter ) ) {
384+ this . submitSearch ( ) ;
385+ keyboardEvent . preventDefault ( ) ;
386+ }
387+
388+ else if ( keyboardEvent . equals ( KeyCode . Escape ) ) {
389+ this . _onSearchCancel . fire ( ) ;
390+ keyboardEvent . preventDefault ( ) ;
391+ }
392+
393+ else if ( keyboardEvent . equals ( KeyCode . Tab ) ) {
394+ if ( this . isReplaceShown ( ) ) {
395+ this . replaceInput . focus ( ) ;
396+ } else {
397+ this . searchInput . focusOnCaseSensitive ( ) ;
398+ }
399+ keyboardEvent . preventDefault ( ) ;
400+ }
401+ }
402+
403+ private onCaseSensitiveKeyDown ( keyboardEvent : IKeyboardEvent ) {
404+ if ( keyboardEvent . equals ( KeyMod . Shift | KeyCode . Tab ) ) {
405+ if ( this . isReplaceShown ( ) ) {
406+ this . replaceInput . focus ( ) ;
407+ keyboardEvent . preventDefault ( ) ;
408+ }
409+ }
410+ }
411+
412+ private onRegexKeyDown ( keyboardEvent : IKeyboardEvent ) {
413+ if ( keyboardEvent . equals ( KeyCode . Tab ) ) {
414+ if ( this . isReplaceActive ( ) ) {
415+ this . focusReplaceAllAction ( ) ;
416+ } else {
417+ this . _onBlur . fire ( ) ;
418+ }
419+ keyboardEvent . preventDefault ( ) ;
379420 }
380421 }
381422
382- private onReplaceInputKeyUp ( keyboardEvent : IKeyboardEvent ) {
383- switch ( keyboardEvent . keyCode ) {
384- case KeyCode . Enter :
385- this . submitSearch ( ) ;
386- return ;
387- default :
388- return ;
423+ private onReplaceInputKeyDown ( keyboardEvent : IKeyboardEvent ) {
424+ if ( keyboardEvent . equals ( KeyCode . Enter ) ) {
425+ this . submitSearch ( ) ;
426+ keyboardEvent . preventDefault ( ) ;
427+ }
428+
429+ else if ( keyboardEvent . equals ( KeyCode . Tab ) ) {
430+ this . searchInput . focusOnCaseSensitive ( ) ;
431+ keyboardEvent . preventDefault ( ) ;
432+ }
433+
434+ else if ( keyboardEvent . equals ( KeyMod . Shift | KeyCode . Tab ) ) {
435+ this . searchInput . focus ( ) ;
436+ keyboardEvent . preventDefault ( ) ;
389437 }
390438 }
391439
0 commit comments