Skip to content

Commit

Permalink
Debounce event handler on notebook editor open. (#162975)
Browse files Browse the repository at this point in the history
  • Loading branch information
rebornix committed Oct 7, 2022
1 parent 6d85cd9 commit 30a8ab3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { Codicon } from 'vs/base/common/codicons';
import { Emitter, Event } from 'vs/base/common/event';
import { combinedDisposable, IDisposable, Disposable, DisposableStore, MutableDisposable, toDisposable } from 'vs/base/common/lifecycle';
import { IThemeService, ThemeIcon } from 'vs/platform/theme/common/themeService';
import { CellRevealType, IActiveNotebookEditor, ICellViewModel, INotebookEditorOptions } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { CellRevealType, IActiveNotebookEditor, ICellViewModel, INotebookEditorOptions, INotebookViewCellsUpdateEvent } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { NotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookEditor';
import { CellKind } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IOutline, IOutlineComparator, IOutlineCreator, IOutlineListConfig, IOutlineService, IQuickPickDataSource, IQuickPickOutlineElement, OutlineChangeEvent, OutlineConfigKeys, OutlineTarget } from 'vs/workbench/services/outline/browser/outline';
Expand Down Expand Up @@ -320,8 +320,16 @@ export class NotebookCellOutline extends Disposable implements IOutline<OutlineE
selectionListener.clear();
} else {
selectionListener.value = combinedDisposable(
notebookEditor.onDidChangeSelection(() => this._recomputeActive()),
notebookEditor.onDidChangeViewCells(() => this._recomputeState())
Event.debounce<void, void>(
notebookEditor.onDidChangeSelection,
(last, _current) => last,
200
)(this._recomputeActive, this),
Event.debounce<INotebookViewCellsUpdateEvent, INotebookViewCellsUpdateEvent>(
notebookEditor.onDidChangeViewCells,
(last, _current) => last ?? _current,
200
)(this._recomputeState, this)
);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,11 @@ export class NotebookEditorToolbar extends Disposable {
this._secondaryActions = [];
this._buildBody();

this._register(this.editorService.onDidActiveEditorChange(() => {
if (this.editorService.activeEditorPane?.getId() === NOTEBOOK_EDITOR_ID) {
const notebookEditor = this.editorService.activeEditorPane.getControl() as INotebookEditorDelegate;
if (notebookEditor === this.notebookEditor) {
// this is the active editor
this._showNotebookActionsinEditorToolbar();
return;
}
}
}));
this._register(Event.debounce<void, void>(
this.editorService.onDidActiveEditorChange,
(last, _current) => last,
200
)(this._updatePerEditorChange, this));

this._registerNotebookActionsToolbar();
}
Expand All @@ -338,6 +333,17 @@ export class NotebookEditorToolbar extends Disposable {
DOM.append(this.domNode, this._notebookTopRightToolbarContainer);
}

private _updatePerEditorChange() {
if (this.editorService.activeEditorPane?.getId() === NOTEBOOK_EDITOR_ID) {
const notebookEditor = this.editorService.activeEditorPane.getControl() as INotebookEditorDelegate;
if (notebookEditor === this.notebookEditor) {
// this is the active editor
this._showNotebookActionsinEditorToolbar();
return;
}
}
}

private _registerNotebookActionsToolbar() {
this._notebookGlobalActionsMenu = this._register(this.menuService.createMenu(this.notebookEditor.creationOptions.menuIds.notebookToolbar, this.contextKeyService));
this._register(this._notebookGlobalActionsMenu);
Expand Down

0 comments on commit 30a8ab3

Please sign in to comment.