Skip to content

Commit a47bf98

Browse files
committed
repl filter: polish
1 parent 7f93f17 commit a47bf98

2 files changed

Lines changed: 22 additions & 32 deletions

File tree

src/vs/workbench/contrib/debug/browser/repl.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
120120

121121
this.history = new HistoryNavigator(JSON.parse(this.storageService.get(HISTORY_STORAGE_KEY, StorageScope.WORKSPACE, '[]')), 50);
122122
this.filter = new ReplFilter();
123-
this.filterState = new ReplFilterState();
123+
this.filterState = new ReplFilterState(this);
124124

125125
codeEditorService.registerDecorationType(DECORATION_KEY, {});
126126
this.registerListeners();
@@ -251,19 +251,10 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
251251
}));
252252
}
253253

254-
private computeFilterStats(): { total: number, filtered: number } {
255-
let filtered = 0;
256-
let total = 0;
257-
if (this.tree) {
258-
total = this.tree.getNode().children.length;
259-
for (const child of this.tree.getNode().children) {
260-
if (child.visible) {
261-
++filtered;
262-
}
263-
}
264-
}
254+
getFilterStats(): { total: number, filtered: number } {
265255
return {
266-
total, filtered
256+
total: this.tree.getNode().children.length,
257+
filtered: this.tree.getNode().children.filter(c => c.visible).length
267258
};
268259
}
269260

@@ -590,7 +581,6 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
590581
}
591582
lastSelectedString = selection ? selection.toString() : '';
592583
}));
593-
this._register(this.tree.onDidChangeContentHeight(() => this.refreshReplElements(false)));
594584
// Make sure to select the session if debugging is already active
595585
this.selectSession();
596586
this.styleElement = dom.createStyleSheet(this.container);
@@ -682,7 +672,6 @@ export class Repl extends ViewPane implements IHistoryNavigationWidget {
682672
}
683673

684674
this.refreshScheduler.schedule(noDelay ? 0 : undefined);
685-
this.filterState.filterStats = this.computeFilterStats();
686675
}
687676
}
688677

src/vs/workbench/contrib/debug/browser/replFilter.ts

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,14 @@ export class ReplFilter implements ITreeFilter<IReplElement> {
7979
}
8080
}
8181

82+
export interface IFilterStatsProvider {
83+
getFilterStats(): { total: number, filtered: number };
84+
}
85+
8286
export class ReplFilterState {
8387

88+
constructor(private filterStatsProvider: IFilterStatsProvider) { }
89+
8490
private readonly _onDidChange: Emitter<void> = new Emitter<void>();
8591
get onDidChange(): Event<void> {
8692
return this._onDidChange.event;
@@ -102,18 +108,16 @@ export class ReplFilterState {
102108
return this._stats;
103109
}
104110

105-
set filterStats(stats: { total: number, filtered: number }) {
106-
const { total, filtered } = stats;
107-
if (this._stats.total !== total || this._stats.filtered !== filtered) {
108-
this._stats = { total, filtered };
109-
this._onDidStatsChange.fire();
110-
}
111-
}
112-
113111
set filterText(filterText: string) {
114112
if (this._filterText !== filterText) {
115113
this._filterText = filterText;
116114
this._onDidChange.fire();
115+
116+
const { total, filtered } = this.filterStatsProvider.getFilterStats();
117+
if (this._stats.total !== total || this._stats.filtered !== filtered) {
118+
this._stats = { total, filtered };
119+
this._onDidStatsChange.fire();
120+
}
117121
}
118122
}
119123
}
@@ -122,7 +126,7 @@ export class ReplFilterActionViewItem extends BaseActionViewItem {
122126

123127
private delayedFilterUpdate: Delayer<void>;
124128
private container!: HTMLElement;
125-
private filterBadge: HTMLElement | null = null;
129+
private filterBadge!: HTMLElement;
126130
private filterInputBox!: HistoryInputBox;
127131

128132
constructor(
@@ -221,15 +225,12 @@ export class ReplFilterActionViewItem extends BaseActionViewItem {
221225
}
222226

223227
private updateBadge(): void {
224-
if (this.filterBadge) {
225-
const { total, filtered } = this.filters.filterStats;
226-
const filterBadgeHidden = total === filtered || total === 0;
228+
const { total, filtered } = this.filters.filterStats;
229+
const filterBadgeHidden = total === filtered || total === 0;
227230

228-
this.filterBadge.classList.toggle('hidden', filterBadgeHidden);
229-
this.filterBadge.textContent = localize('showing filtered repl lines', "Showing {0} of {1}", filtered, total);
230-
231-
this.filterInputBox.inputElement.style.paddingRight = filterBadgeHidden ? '4px' : '150px';
232-
}
231+
this.filterBadge.classList.toggle('hidden', filterBadgeHidden);
232+
this.filterBadge.textContent = localize('showing filtered repl lines', "Showing {0} of {1}", filtered, total);
233+
this.filterInputBox.inputElement.style.paddingRight = filterBadgeHidden ? '4px' : '150px';
233234
}
234235

235236
protected get class(): string {

0 commit comments

Comments
 (0)