@@ -15,7 +15,7 @@ import { IAction } from 'vs/base/common/actions';
1515import { HistoryInputBox } from 'vs/base/browser/ui/inputbox/inputBox' ;
1616import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation' ;
1717import { IContextViewService } from 'vs/platform/contextview/browser/contextView' ;
18- import { toDisposable , Disposable } from 'vs/base/common/lifecycle' ;
18+ import { toDisposable } from 'vs/base/common/lifecycle' ;
1919import { Event , Emitter } from 'vs/base/common/event' ;
2020import { StandardKeyboardEvent } from 'vs/base/browser/keyboardEvent' ;
2121import { KeyCode } from 'vs/base/common/keyCodes' ;
@@ -76,64 +76,37 @@ export class ReplFilter implements ITreeFilter<IReplElement> {
7676 }
7777}
7878
79- export interface IReplFiltersChangeEvent {
80- filterText ?: boolean ;
81- layout ?: boolean ;
82- }
83-
84- export interface IReplFiltersOptions {
85- filterText : string ;
86- filterHistory : string [ ] ;
87- layout : DOM . Dimension ;
88- }
89-
90- export class TreeFilterState extends Disposable {
79+ export class ReplFilterState {
9180
92- private readonly _onDidChange : Emitter < IReplFiltersChangeEvent > = this . _register ( new Emitter < IReplFiltersChangeEvent > ( ) ) ;
93- readonly onDidChange : Event < IReplFiltersChangeEvent > = this . _onDidChange . event ;
94-
95- constructor ( options : IReplFiltersOptions ) {
96- super ( ) ;
97- this . _filterText = options . filterText ;
98- this . filterHistory = options . filterHistory ;
99- this . _layout = options . layout ;
81+ private readonly _onDidChange : Emitter < void > = new Emitter < void > ( ) ;
82+ get onDidChange ( ) : Event < void > {
83+ return this . _onDidChange . event ;
10084 }
10185
102- private _filterText : string ;
86+ private _filterText = '' ;
87+
10388 get filterText ( ) : string {
10489 return this . _filterText ;
10590 }
91+
10692 set filterText ( filterText : string ) {
10793 if ( this . _filterText !== filterText ) {
10894 this . _filterText = filterText ;
109- this . _onDidChange . fire ( { filterText : true } ) ;
110- }
111- }
112-
113- filterHistory : string [ ] ;
114-
115- private _layout : DOM . Dimension = new DOM . Dimension ( 0 , 0 ) ;
116- get layout ( ) : DOM . Dimension {
117- return this . _layout ;
118- }
119- set layout ( layout : DOM . Dimension ) {
120- if ( this . _layout . width !== layout . width || this . _layout . height !== layout . height ) {
121- this . _layout = layout ;
122- this . _onDidChange . fire ( < IReplFiltersChangeEvent > { layout : true } ) ;
95+ this . _onDidChange . fire ( ) ;
12396 }
12497 }
12598}
12699
127- export class TreeFilterPanelActionViewItem extends BaseActionViewItem {
100+ export class ReplFilterActionViewItem extends BaseActionViewItem {
128101
129102 private delayedFilterUpdate : Delayer < void > ;
130- private container : HTMLElement | undefined ;
131- private filterInputBox : HistoryInputBox | undefined ;
103+ private container ! : HTMLElement ;
104+ private filterInputBox ! : HistoryInputBox ;
132105
133106 constructor (
134107 action : IAction ,
135108 private placeholder : string ,
136- private filters : TreeFilterState ,
109+ private filters : ReplFilterState ,
137110 @IInstantiationService private readonly instantiationService : IInstantiationService ,
138111 @IThemeService private readonly themeService : IThemeService ,
139112 @IContextViewService private readonly contextViewService : IContextViewService ) {
@@ -150,34 +123,28 @@ export class TreeFilterPanelActionViewItem extends BaseActionViewItem {
150123 this . element . className = this . class ;
151124 this . createInput ( this . element ) ;
152125 this . updateClass ( ) ;
153-
154- this . adjustInputBox ( ) ;
126+ this . filterInputBox . inputElement . style . paddingRight = DOM . hasClass ( this . element , 'small' ) ? '25px' : '150px' ;
155127 }
156128
157129 focus ( ) : void {
158- if ( this . filterInputBox ) {
159- this . filterInputBox . focus ( ) ;
160- }
130+ this . filterInputBox . focus ( ) ;
161131 }
162132
163133 private clearFilterText ( ) : void {
164- if ( this . filterInputBox ) {
165- this . filterInputBox . value = '' ;
166- }
134+ this . filterInputBox . value = '' ;
167135 }
168136
169137 private createInput ( container : HTMLElement ) : void {
170138 this . filterInputBox = this . _register ( this . instantiationService . createInstance ( ContextScopedHistoryInputBox , container , this . contextViewService , {
171139 placeholder : this . placeholder ,
172- history : this . filters . filterHistory
140+ history : [ ]
173141 } ) ) ;
174142 this . _register ( attachInputBoxStyler ( this . filterInputBox , this . themeService ) ) ;
175143 this . filterInputBox . value = this . filters . filterText ;
144+
176145 this . _register ( this . filterInputBox . onDidChange ( ( ) => this . delayedFilterUpdate . trigger ( ( ) => this . onDidInputChange ( this . filterInputBox ! ) ) ) ) ;
177- this . _register ( this . filters . onDidChange ( ( event : IReplFiltersChangeEvent ) => {
178- if ( event . filterText ) {
179- this . filterInputBox ! . value = this . filters . filterText ;
180- }
146+ this . _register ( this . filters . onDidChange ( ( ) => {
147+ this . filterInputBox . value = this . filters . filterText ;
181148 } ) ) ;
182149 this . _register ( DOM . addStandardDisposableListener ( this . filterInputBox . inputElement , DOM . EventType . KEY_DOWN , ( e : any ) => this . onInputKeyDown ( e ) ) ) ;
183150 this . _register ( DOM . addStandardDisposableListener ( container , DOM . EventType . KEY_DOWN , this . handleKeyboardEvent ) ) ;
@@ -186,19 +153,11 @@ export class TreeFilterPanelActionViewItem extends BaseActionViewItem {
186153 e . stopPropagation ( ) ;
187154 e . preventDefault ( ) ;
188155 } ) ) ;
189- this . _register ( this . filters . onDidChange ( e => this . onDidFiltersChange ( e ) ) ) ;
190- }
191-
192- private onDidFiltersChange ( e : IReplFiltersChangeEvent ) : void {
193- if ( e . layout ) {
194- this . updateClass ( ) ;
195- }
196156 }
197157
198158 private onDidInputChange ( inputbox : HistoryInputBox ) {
199159 inputbox . addToHistory ( ) ;
200160 this . filters . filterText = inputbox . value ;
201- this . filters . filterHistory = inputbox . getHistory ( ) ;
202161 }
203162
204163 // Action toolbar is swallowing some keys for action items which should not be for an input box
@@ -220,27 +179,7 @@ export class TreeFilterPanelActionViewItem extends BaseActionViewItem {
220179 }
221180 }
222181
223- private adjustInputBox ( ) : void {
224- if ( this . element && this . filterInputBox ) {
225- this . filterInputBox . inputElement . style . paddingRight = DOM . hasClass ( this . element , 'small' ) ? '25px' : '150px' ;
226- }
227- }
228-
229- protected updateClass ( ) : void {
230- if ( this . element && this . container ) {
231- this . element . className = this . class ;
232- DOM . toggleClass ( this . container , 'grow' , DOM . hasClass ( this . element , 'grow' ) ) ;
233- this . adjustInputBox ( ) ;
234- }
235- }
236-
237182 protected get class ( ) : string {
238- if ( this . filters . layout . width > 800 ) {
239- return 'panel-action-tree-filter grow' ;
240- } else if ( this . filters . layout . width < 600 ) {
241- return 'panel-action-tree-filter small' ;
242- } else {
243- return 'panel-action-tree-filter' ;
244- }
183+ return 'panel-action-tree-filter' ;
245184 }
246185}
0 commit comments