Skip to content

Commit 2372c8c

Browse files
authored
Debounce computing active item in notebook outline (microsoft#210583)
1 parent e3f691d commit 2372c8c

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/vs/workbench/contrib/notebook/browser/viewModel/notebookOutlineProvider.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export class NotebookCellOutlineProvider {
4242
}
4343

4444
private readonly _outlineEntryFactory: NotebookOutlineEntryFactory;
45+
private readonly delayRecomputeActive: () => void;
4546
constructor(
4647
private readonly _editor: INotebookEditor,
4748
private readonly _target: OutlineTarget,
@@ -52,20 +53,27 @@ export class NotebookCellOutlineProvider {
5253
@IConfigurationService private readonly _configurationService: IConfigurationService,
5354
) {
5455
this._outlineEntryFactory = new NotebookOutlineEntryFactory(notebookExecutionStateService);
56+
const delayerRecomputeActive = this._disposables.add(new Delayer(10));
57+
this.delayRecomputeActive = () => delayerRecomputeActive.trigger(() => {
58+
const { changeEventTriggered } = this._recomputeActive();
59+
if (!changeEventTriggered) {
60+
this._onDidChange.fire({});
61+
}
62+
});
5563

5664
this._disposables.add(Event.debounce<void, void>(
5765
_editor.onDidChangeSelection,
5866
(last, _current) => last,
5967
200
6068
)(() => {
61-
this._recomputeActive();
69+
this.delayRecomputeActive();
6270
}, this))
6371
this._disposables.add(Event.debounce<INotebookViewCellsUpdateEvent, INotebookViewCellsUpdateEvent>(
6472
_editor.onDidChangeViewCells,
6573
(last, _current) => last ?? _current,
6674
200
6775
)(() => {
68-
this._recomputeActive();
76+
this.delayRecomputeActive();
6977
}, this)
7078
);
7179

@@ -253,10 +261,7 @@ export class NotebookCellOutlineProvider {
253261
}
254262
}));
255263

256-
const { changeEventTriggered } = this._recomputeActive();
257-
if (!changeEventTriggered) {
258-
this._onDidChange.fire({});
259-
}
264+
this.delayRecomputeActive();
260265
}
261266

262267
private _recomputeActive(): { changeEventTriggered: boolean } {

0 commit comments

Comments
 (0)