diff --git a/src/diff/cell.ts b/src/diff/cell.ts index fdbf1eb..a3e2b07 100644 --- a/src/diff/cell.ts +++ b/src/diff/cell.ts @@ -60,8 +60,16 @@ class CodeMirrorSplitDiffWidget extends BaseDiffWidget { extensions: [ basicSetup, python(), - EditorView.editable.of(false), - jupyterTheme + EditorView.editable.of(true), + jupyterTheme, + EditorView.updateListener.of(update => { + if (update.docChanged) { + const newText = update.state.doc.toString(); + + this._modifiedCode = newText; + this._newSource = newText; + } + }) ] }, parent: this.node diff --git a/src/widget.ts b/src/widget.ts index e37ef67..a744f16 100644 --- a/src/widget.ts +++ b/src/widget.ts @@ -100,7 +100,7 @@ export abstract class BaseDiffWidget extends Widget { */ public onAcceptClick(): void { if (this._cell) { - this._cell.sharedModel.setSource(this._newSource); + this._cell.sharedModel.setSource(this._newSource || this._originalSource); this._closeDiffView(); } } @@ -191,9 +191,9 @@ export abstract class BaseDiffWidget extends Widget { private _cell: ICellModel; private _cellFooterTracker: ICellFooterTracker; private _originalSource: string; - private _newSource: string; private _showActionButtons: boolean; private _openDiff: boolean; private _toggleButton: ToolbarButton | null = null; private _trans: TranslationBundle; + public _newSource: string; }