Skip to content

Commit 5cde286

Browse files
authored
show unified diff for rendered markdown cells by switching to edit mode (#31)
1 parent b5cf575 commit 5cde286

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/diff/unified-cell.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Cell } from '@jupyterlab/cells';
1+
import { Cell, MarkdownCell } from '@jupyterlab/cells';
22
import { checkIcon, ToolbarButton, undoIcon } from '@jupyterlab/ui-components';
33
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
44
import {
@@ -38,6 +38,7 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
3838

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

4243
/**
4344
* Get the shared model for source manipulation
@@ -50,6 +51,15 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
5051
* Activate the diff view without cell toolbar.
5152
*/
5253
protected activate(): void {
54+
const { model } = this._cell;
55+
if (model.type === 'markdown') {
56+
const md = this._cell as MarkdownCell;
57+
if (md.rendered) {
58+
this._wasRendered = true;
59+
md.rendered = false;
60+
}
61+
}
62+
5363
super.activate();
5464
UnifiedCellDiffManager._activeDiffCount++;
5565

@@ -75,6 +85,11 @@ export class UnifiedCellDiffManager extends BaseUnifiedDiffManager {
7585
UnifiedCellDiffManager._activeDiffCount - 1
7686
);
7787

88+
if (this._wasRendered && this._cell.model.type === 'markdown') {
89+
(this._cell as MarkdownCell).rendered = true;
90+
this._wasRendered = false;
91+
}
92+
7893
if (this._toolbarObserver) {
7994
this._toolbarObserver.disconnect();
8095
this._toolbarObserver = undefined;

0 commit comments

Comments
 (0)