@jupyterlab/notebook 4.6.3 → 4.6.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ import type { IObservableList, IObservableMap } from '@jupyterlab/observables';
26
26
  import type { ITranslator } from '@jupyterlab/translation';
27
27
  import { nullTranslator } from '@jupyterlab/translation';
28
28
  import { ArrayExt } from '@lumino/algorithm';
29
+ import { Debouncer } from '@lumino/polling';
29
30
  import type { Widget } from '@lumino/widgets';
30
31
  import type { CellList } from './celllist';
31
32
  import { NotebookPanel } from './panel';
@@ -68,18 +69,9 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
68
69
 
69
70
  private _onNotebookStateChanged(_: Notebook, args: IChangedArgs<any>) {
70
71
  if (args.name === 'mode') {
71
- // Delay the update to ensure that `document.activeElement` settled.
72
- window.setTimeout(() => {
73
- if (
74
- args.newValue === 'command' &&
75
- document.activeElement?.closest('.jp-DocumentSearch-overlay')
76
- ) {
77
- // Do not request updating mode when user switched focus to search overlay.
78
- return;
79
- }
80
- this._updateSelectionMode();
81
- this._filtersChanged.emit();
82
- }, 0);
72
+ // Debounce to ensure that `document.activeElement` settled, and to keep
73
+ // only the most recent mode transition.
74
+ void this._modeChangeDebouncer.invoke();
83
75
  }
84
76
  }
85
77
 
@@ -208,6 +200,8 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
208
200
  );
209
201
  this._stopObservingLastCell();
210
202
 
203
+ this._modeChangeDebouncer.dispose();
204
+
211
205
  super.dispose();
212
206
 
213
207
  const index = this.widget.content.activeCellIndex;
@@ -932,6 +926,19 @@ export class NotebookSearchProvider extends SearchProvider<NotebookPanel> {
932
926
  protected delayedActiveCellChangeHandlerReady: Promise<void>;
933
927
  private _currentProviderIndex: number | null = null;
934
928
  private _delayedActiveCellChangeHandler: number | null = null;
929
+ private _modeChangeDebouncer = new Debouncer(() => {
930
+ // The mode can change again before this handler runs; check the
931
+ // current mode because this is what `_updateSelectionMode()` acts on.
932
+ if (
933
+ this.widget.content.mode === 'command' &&
934
+ document.activeElement?.closest('.jp-DocumentSearch-overlay')
935
+ ) {
936
+ // Do not request updating mode when user switched focus to search overlay.
937
+ return;
938
+ }
939
+ this._updateSelectionMode();
940
+ this._filtersChanged.emit();
941
+ }, 0);
935
942
  private _filters: IFilters | undefined;
936
943
  private _onSelection = false;
937
944
  private _selectedCells: number = 1;
package/src/widget.ts CHANGED
@@ -618,7 +618,7 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
618
618
  for (const cell of cells) {
619
619
  this._insertCell(++index, cell);
620
620
  }
621
- this._syncMarkdownCellTrust();
621
+ this._syncCellTrust();
622
622
  newValue.cells.changed.connect(this._onCellsChanged, this);
623
623
  newValue.metadataChanged.connect(this.onMetadataChanged, this);
624
624
  newValue.contentChanged.connect(this.onModelContentChanged, this);
@@ -680,7 +680,7 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
680
680
  this.addHeader();
681
681
  }
682
682
 
683
- this._syncMarkdownCellTrust();
683
+ this._syncCellTrust();
684
684
  this.update();
685
685
  }
686
686
 
@@ -708,7 +708,7 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
708
708
  widget.addClass(NB_CELL_CLASS);
709
709
 
710
710
  ArrayExt.insert(this.cellsArray, index, widget);
711
- this._syncMarkdownCellTrust(widget);
711
+ this._syncCellTrust(widget);
712
712
  this.onCellInserted(index, widget);
713
713
 
714
714
  this._scheduleCellRenderOnIdle();
@@ -818,8 +818,8 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
818
818
  widget.dispose();
819
819
  }
820
820
 
821
- private _shouldTrustMarkdown(): boolean {
822
- // Note: this returns false in a notebook without trsuted code cells;
821
+ private _shouldTrustCell(): boolean {
822
+ // Note: this returns false in a notebook without trusted code cells;
823
823
  // This is intended since only Code cells carry trust status on disk.
824
824
  if (!this._notebookModel) {
825
825
  return false;
@@ -836,13 +836,19 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
836
836
  return hasCodeCell;
837
837
  }
838
838
 
839
- private _syncMarkdownCellTrust(cell?: Cell): void {
840
- const trusted = this._shouldTrustMarkdown();
839
+ private _syncCellTrust(cell?: Cell): void {
840
+ const trusted = this._shouldTrustCell();
841
841
  const trustHandler = this.rendermime.trustHandler;
842
842
  if (!trustHandler) {
843
843
  return;
844
844
  }
845
845
 
846
+ if (trusted) {
847
+ trustHandler.markTrusted(this.node);
848
+ } else {
849
+ trustHandler.unmarkTrusted(this.node);
850
+ }
851
+
846
852
  const cells = cell ? [cell] : this.widgets;
847
853
  for (const widget of cells) {
848
854
  if (!(widget instanceof MarkdownCell)) {
@@ -861,7 +867,7 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
861
867
  args: IChangedArgs<any>
862
868
  ): void {
863
869
  if (args.name === 'trusted') {
864
- this._syncMarkdownCellTrust();
870
+ this._syncCellTrust();
865
871
  }
866
872
  }
867
873
 
@@ -1203,7 +1209,7 @@ export class StaticNotebook extends WindowedList<NotebookViewModel> {
1203
1209
  this._contentVisibilityObserver!.observe(cell.node);
1204
1210
  });
1205
1211
  });
1206
- });
1212
+ }, this);
1207
1213
  }
1208
1214
 
1209
1215
  protected cellsArray: Array<Cell>;