Skip to content

Commit f8c01e3

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
fix: list view filtering when opening the view
When the widget is opened the first time with any search options, the widget might miss the refresh event as it does not happen at instantiation time. This PR ensures that all list widget refresh events wait until the React component is rendered and is visible in the UI. This change also ensures that the debounced search will run with the most recent search options by setting the `trailing` property of the debounced function to `true`. Closes #1740 Signed-off-by: Akos Kitta <[email protected]>
1 parent af468a7 commit f8c01e3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Diff for: arduino-ide-extension/src/browser/widgets/component-list/filterable-list-container.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class FilterableListContainer<
3232
}
3333

3434
override componentDidMount(): void {
35-
this.search = debounce(this.search, 500);
35+
this.search = debounce(this.search, 500, { trailing: true });
3636
this.search(this.state.searchOptions);
3737
this.props.searchOptionsDidChange((newSearchOptions) => {
3838
const { searchOptions } = this.state;

Diff for: arduino-ide-extension/src/browser/widgets/component-list/list-widget.tsx

+6-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import { Widget } from '@theia/core/shared/@phosphor/widgets';
88
import { Message } from '@theia/core/shared/@phosphor/messaging';
99
import { Emitter } from '@theia/core/lib/common/event';
10+
import { Deferred } from '@theia/core/lib/common/promise-util';
1011
import { ReactWidget } from '@theia/core/lib/browser/widgets/react-widget';
1112
import { CommandService } from '@theia/core/lib/common/command';
1213
import { MessageService } from '@theia/core/lib/common/message-service';
@@ -42,6 +43,7 @@ export abstract class ListWidget<
4243
* Do not touch or use it. It is for setting the focus on the `input` after the widget activation.
4344
*/
4445
protected focusNode: HTMLElement | undefined;
46+
private readonly didReceiveFirstFocus = new Deferred();
4547
protected readonly searchOptionsChangeEmitter = new Emitter<
4648
Partial<S> | undefined
4749
>();
@@ -117,6 +119,7 @@ export abstract class ListWidget<
117119

118120
protected onFocusResolved = (element: HTMLElement | undefined): void => {
119121
this.focusNode = element;
122+
this.didReceiveFirstFocus.resolve();
120123
};
121124

122125
protected async install({
@@ -192,7 +195,9 @@ export abstract class ListWidget<
192195
* If it is `undefined`, updates the view state by re-running the search with the current `filterText` term.
193196
*/
194197
refresh(searchOptions: Partial<S> | undefined): void {
195-
this.searchOptionsChangeEmitter.fire(searchOptions);
198+
this.didReceiveFirstFocus.promise.then(() =>
199+
this.searchOptionsChangeEmitter.fire(searchOptions)
200+
);
196201
}
197202

198203
updateScrollBar(): void {

0 commit comments

Comments
 (0)