Skip to content

Commit c7ed41e

Browse files
authored
Merge branch 'main' into fix23
2 parents 63eee78 + b5cf575 commit c7ed41e

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

src/diff/base-unified-diff.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export abstract class BaseUnifiedDiffManager {
6969
return;
7070
}
7171
this._isDisposed = true;
72-
this._deactivate();
72+
this.deactivate();
7373
}
7474

7575
/**
@@ -112,7 +112,7 @@ export abstract class BaseUnifiedDiffManager {
112112
/**
113113
* Deactivate the diff view
114114
*/
115-
protected _deactivate(): void {
115+
protected deactivate(): void {
116116
this.removeToolbarButtons();
117117
this._cleanupEditor();
118118
this.showCellToolbar();
@@ -135,11 +135,9 @@ export abstract class BaseUnifiedDiffManager {
135135
/**
136136
* Accept all changes
137137
*/
138-
public acceptAll(): void {
139-
const sharedModel = this.getSharedModel();
140-
this._originalSource = sharedModel.getSource();
141-
this._newSource = this._originalSource;
142-
this._deactivate();
138+
protected acceptAll(): void {
139+
// simply accept the current state
140+
this.deactivate();
143141
}
144142

145143
/**
@@ -148,8 +146,7 @@ export abstract class BaseUnifiedDiffManager {
148146
public rejectAll(): void {
149147
const sharedModel = this.getSharedModel();
150148
sharedModel.setSource(this._originalSource);
151-
this._newSource = this._originalSource;
152-
this._deactivate();
149+
this.deactivate();
153150
}
154151

155152
/**
@@ -169,7 +166,7 @@ export abstract class BaseUnifiedDiffManager {
169166
newSource: this._newSource,
170167
isInitialized: this._isInitialized,
171168
sharedModel: this.getSharedModel(),
172-
onChunkChange: () => this._deactivate()
169+
onChunkChange: () => this.deactivate()
173170
});
174171

175172
this._isInitialized = true;

src/diff/unified-cell.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
3838
}
3939

4040
private static _activeDiffCount = 0;
41+
private _toolbarObserver?: MutationObserver;
4142

4243
/**
4344
* Check if this cell still has pending changes
@@ -69,29 +70,32 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
6970
subtree: true
7071
});
7172

72-
(this as any)._toolbarObserver = observer;
73+
this._toolbarObserver = observer;
7374
}
7475

7576
/**
7677
* Deactivate the diff view with cell toolbar.
7778
*/
78-
protected _deactivate(): void {
79-
super['_deactivate']();
79+
protected deactivate(): void {
80+
super.deactivate();
8081
UnifiedCellDiffManager._activeDiffCount = Math.max(
8182
0,
8283
UnifiedCellDiffManager._activeDiffCount - 1
8384
);
8485

85-
const observer = (this as any)._toolbarObserver as MutationObserver;
86-
if (observer) {
87-
observer.disconnect();
86+
if (this._toolbarObserver) {
87+
this._toolbarObserver.disconnect();
88+
this._toolbarObserver = undefined;
8889
}
8990
}
91+
9092
/**
9193
* Hide the cell's toolbar while the diff is active
9294
*/
9395
protected hideCellToolbar(): void {
94-
const toolbar = this._cell.node.querySelector('jp-toolbar') as HTMLElement;
96+
const toolbar = this._cell.node.querySelector(
97+
'jp-toolbar'
98+
) as HTMLElement | null;
9599
if (toolbar) {
96100
toolbar.style.display = 'none';
97101
}

0 commit comments

Comments
 (0)