@@ -16,13 +16,18 @@ import { IThemeService } from 'vs/platform/theme/common/themeService';
1616import { attachInputBoxStyler , attachCheckboxStyler } from 'vs/platform/theme/common/styler' ;
1717import { ContextScopedHistoryInputBox } from 'vs/platform/browser/contextScopedHistoryWidget' ;
1818import { IContextKeyService } from 'vs/platform/contextkey/common/contextkey' ;
19+ import { IConfigurationService } from 'vs/platform/configuration/common/configuration' ;
20+ import { ISearchConfigurationProperties } from 'vs/workbench/services/search/common/search' ;
21+ import { Delayer } from 'vs/base/common/async' ;
1922
2023export interface IOptions {
2124 placeholder ?: string ;
2225 width ?: number ;
2326 validation ?: IInputValidator ;
2427 ariaLabel ?: string ;
2528 history ?: string [ ] ;
29+ submitOnType ?: boolean ;
30+ submitOnTypeDelay ?: number ;
2631}
2732
2833export class PatternInputWidget extends Widget {
@@ -38,21 +43,26 @@ export class PatternInputWidget extends Widget {
3843 private domNode ! : HTMLElement ;
3944 protected inputBox ! : HistoryInputBox ;
4045
41- private _onSubmit = this . _register ( new Emitter < boolean > ( ) ) ;
42- onSubmit : CommonEvent < boolean > = this . _onSubmit . event ;
46+ private _onSubmit = this . _register ( new Emitter < void > ( ) ) ;
47+ onSubmit : CommonEvent < void > = this . _onSubmit . event ;
4348
44- private _onCancel = this . _register ( new Emitter < boolean > ( ) ) ;
45- onCancel : CommonEvent < boolean > = this . _onCancel . event ;
49+ private _onCancel = this . _register ( new Emitter < void > ( ) ) ;
50+ onCancel : CommonEvent < void > = this . _onCancel . event ;
51+
52+ private searchOnTypeDelayer : Delayer < void > ;
4653
4754 constructor ( parent : HTMLElement , private contextViewProvider : IContextViewProvider , options : IOptions = Object . create ( null ) ,
4855 @IThemeService protected themeService : IThemeService ,
56+ @IConfigurationService private configurationService : IConfigurationService ,
4957 @IContextKeyService private readonly contextKeyService : IContextKeyService
5058 ) {
5159 super ( ) ;
5260 this . width = options . width || 100 ;
5361 this . placeholder = options . placeholder || '' ;
5462 this . ariaLabel = options . ariaLabel || nls . localize ( 'defaultLabel' , "input" ) ;
5563
64+ this . _register ( this . searchOnTypeDelayer = new Delayer ( this . searchConfig . searchOnTypeDebouncePeriod ) ) ;
65+
5666 this . render ( options ) ;
5767
5868 parent . appendChild ( this . domNode ) ;
@@ -139,6 +149,12 @@ export class PatternInputWidget extends Widget {
139149 this . _register ( attachInputBoxStyler ( this . inputBox , this . themeService ) ) ;
140150 this . inputFocusTracker = dom . trackFocus ( this . inputBox . inputElement ) ;
141151 this . onkeyup ( this . inputBox . inputElement , ( keyboardEvent ) => this . onInputKeyUp ( keyboardEvent ) ) ;
152+ this . _register ( this . inputBox . onDidChange ( ( ) => {
153+ if ( this . searchConfig . searchOnType ) {
154+ this . _onCancel . fire ( ) ;
155+ this . searchOnTypeDelayer . trigger ( ( ) => this . _onSubmit . fire ( ) , this . searchConfig . searchOnTypeDebouncePeriod ) ;
156+ }
157+ } ) ) ;
142158
143159 const controls = document . createElement ( 'div' ) ;
144160 controls . className = 'controls' ;
@@ -154,15 +170,19 @@ export class PatternInputWidget extends Widget {
154170 private onInputKeyUp ( keyboardEvent : IKeyboardEvent ) {
155171 switch ( keyboardEvent . keyCode ) {
156172 case KeyCode . Enter :
157- this . _onSubmit . fire ( false ) ;
173+ this . _onSubmit . fire ( ) ;
158174 return ;
159175 case KeyCode . Escape :
160- this . _onCancel . fire ( false ) ;
176+ this . _onCancel . fire ( ) ;
161177 return ;
162178 default :
163179 return ;
164180 }
165181 }
182+
183+ get searchConfig ( ) {
184+ return this . configurationService . getValue < ISearchConfigurationProperties > ( 'search' ) ;
185+ }
166186}
167187
168188export class ExcludePatternInputWidget extends PatternInputWidget {
@@ -172,9 +192,10 @@ export class ExcludePatternInputWidget extends PatternInputWidget {
172192
173193 constructor ( parent : HTMLElement , contextViewProvider : IContextViewProvider , options : IOptions = Object . create ( null ) ,
174194 @IThemeService themeService : IThemeService ,
195+ @IConfigurationService configurationService : IConfigurationService ,
175196 @IContextKeyService contextKeyService : IContextKeyService
176197 ) {
177- super ( parent , contextViewProvider , options , themeService , contextKeyService ) ;
198+ super ( parent , contextViewProvider , options , themeService , configurationService , contextKeyService ) ;
178199 }
179200
180201 private useExcludesAndIgnoreFilesBox ! : Checkbox ;
0 commit comments