diff --git a/src/diff/base-unified-diff.ts b/src/diff/base-unified-diff.ts index e694f9a..cd899a6 100644 --- a/src/diff/base-unified-diff.ts +++ b/src/diff/base-unified-diff.ts @@ -69,7 +69,7 @@ export abstract class BaseUnifiedDiffManager { return; } this._isDisposed = true; - this._deactivate(); + this.deactivate(); } /** @@ -112,7 +112,7 @@ export abstract class BaseUnifiedDiffManager { /** * Deactivate the diff view */ - protected _deactivate(): void { + protected deactivate(): void { this.removeToolbarButtons(); this._cleanupEditor(); this.showCellToolbar(); @@ -137,7 +137,7 @@ export abstract class BaseUnifiedDiffManager { */ protected acceptAll(): void { // simply accept the current state - this._deactivate(); + this.deactivate(); } /** @@ -146,7 +146,7 @@ export abstract class BaseUnifiedDiffManager { protected rejectAll(): void { const sharedModel = this.getSharedModel(); sharedModel.setSource(this._originalSource); - this._deactivate(); + this.deactivate(); } /** @@ -166,7 +166,7 @@ export abstract class BaseUnifiedDiffManager { newSource: this._newSource, isInitialized: this._isInitialized, sharedModel: this.getSharedModel(), - onChunkChange: () => this._deactivate() + onChunkChange: () => this.deactivate() }); this._isInitialized = true; diff --git a/src/diff/unified-cell.ts b/src/diff/unified-cell.ts index db7840b..b98cc2a 100644 --- a/src/diff/unified-cell.ts +++ b/src/diff/unified-cell.ts @@ -37,6 +37,7 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager { } private static _activeDiffCount = 0; + private _toolbarObserver?: MutationObserver; /** * Get the shared model for source manipulation @@ -61,29 +62,32 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager { subtree: true }); - (this as any)._toolbarObserver = observer; + this._toolbarObserver = observer; } /** * Deactivate the diff view with cell toolbar. */ - protected _deactivate(): void { - super['_deactivate'](); + protected deactivate(): void { + super.deactivate(); UnifiedCellDiffManager._activeDiffCount = Math.max( 0, UnifiedCellDiffManager._activeDiffCount - 1 ); - const observer = (this as any)._toolbarObserver as MutationObserver; - if (observer) { - observer.disconnect(); + if (this._toolbarObserver) { + this._toolbarObserver.disconnect(); + this._toolbarObserver = undefined; } } + /** * Hide the cell's toolbar while the diff is active */ protected hideCellToolbar(): void { - const toolbar = this._cell.node.querySelector('jp-toolbar') as HTMLElement; + const toolbar = this._cell.node.querySelector( + 'jp-toolbar' + ) as HTMLElement | null; if (toolbar) { toolbar.style.display = 'none'; }