Skip to content

Commit 6df96b1

Browse files
committed
cleanup
1 parent b83f1b7 commit 6df96b1

File tree

3 files changed

+20
-106
lines changed

3 files changed

+20
-106
lines changed

src/diff/codemirror.ts

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { python } from '@codemirror/lang-python';
22
import { MergeView } from '@codemirror/merge';
33
import { EditorView } from '@codemirror/view';
4-
import { ICellModel } from '@jupyterlab/cells';
54
import { jupyterTheme } from '@jupyterlab/codemirror';
65
import { Message } from '@lumino/messaging';
76
import { Widget } from '@lumino/widgets';
87
import { basicSetup } from 'codemirror';
9-
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
108
import { IDiffStrategy, IDiffWidgetOptions } from '../interfaces';
119
import { BaseDiffWidget } from '../widget';
1210

@@ -30,11 +28,9 @@ export class CodeMirrorStrategy implements IDiffStrategy {
3028
openDiff = true
3129
} = options;
3230

33-
const modifiedCode = newSource || cell.sharedModel.getSource();
34-
3531
const diffWidget = new CodeMirrorDiffWidget({
36-
originalCode: originalSource,
37-
modifiedCode,
32+
originalSource,
33+
newSource,
3834
cell,
3935
cellFooterTracker,
4036
showActionButtons,
@@ -52,24 +48,13 @@ export class CodeMirrorStrategy implements IDiffStrategy {
5248
* A Lumino widget that contains a CodeMirror diff view
5349
*/
5450
class CodeMirrorDiffWidget extends BaseDiffWidget {
55-
private _originalCode: string;
56-
private _modifiedCode: string;
57-
private _mergeView: MergeView | null = null;
58-
5951
/**
6052
* Construct a new CodeMirrorDiffWidget.
6153
*/
62-
constructor(options: CodeMirrorDiffWidget.IOptions) {
63-
super({
64-
cell: options.cell,
65-
cellFooterTracker: options.cellFooterTracker,
66-
originalSource: options.originalCode,
67-
newSource: options.modifiedCode,
68-
showActionButtons: options.showActionButtons,
69-
openDiff: options.openDiff
70-
});
71-
this._originalCode = options.originalCode;
72-
this._modifiedCode = options.modifiedCode;
54+
constructor(options: IDiffWidgetOptions) {
55+
super(options);
56+
this._originalCode = options.originalSource;
57+
this._modifiedCode = options.newSource;
7358
this.addClass('jp-DiffView');
7459
}
7560

@@ -129,21 +114,8 @@ class CodeMirrorDiffWidget extends BaseDiffWidget {
129114
this._mergeView = null;
130115
}
131116
}
132-
}
133117

134-
/**
135-
* A namespace for `CodeMirrorDiffWidget` statics.
136-
*/
137-
namespace CodeMirrorDiffWidget {
138-
/**
139-
* The options used to construct a `CodeMirrorDiffWidget`.
140-
*/
141-
export interface IOptions {
142-
originalCode: string;
143-
modifiedCode: string;
144-
cell: ICellModel;
145-
cellFooterTracker: ICellFooterTracker;
146-
showActionButtons?: boolean;
147-
openDiff?: boolean;
148-
}
118+
private _originalCode: string;
119+
private _modifiedCode: string;
120+
private _mergeView: MergeView | null = null;
149121
}

src/diff/nbdime.ts

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { IDiffEntry } from 'nbdime/lib/diff/diffentries';
33
import { createPatchStringDiffModel } from 'nbdime/lib/diff/model';
44
import { MergeView } from 'nbdime/lib/common/mergeview';
55
import { Widget } from '@lumino/widgets';
6-
import { ICellModel } from '@jupyterlab/cells';
7-
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
86
import { BaseDiffWidget } from '../widget';
97

108
/**
@@ -64,14 +62,7 @@ class NBDimeDiffWidget extends BaseDiffWidget {
6462
* Construct a new NBDimeDiffWidget.
6563
*/
6664
constructor(options: NBDimeDiffWidget.IOptions) {
67-
super({
68-
cell: options.cell,
69-
cellFooterTracker: options.cellFooterTracker,
70-
originalSource: options.originalSource,
71-
newSource: options.newSource,
72-
showActionButtons: options.showActionButtons,
73-
openDiff: options.openDiff
74-
});
65+
super(options);
7566

7667
// Create the NBDime merge view as a child widget
7768
this._mergeView = new MergeView({ remote: options.remote });
@@ -93,13 +84,7 @@ namespace NBDimeDiffWidget {
9384
/**
9485
* The options used to construct a `NBDimeDiffWidget`.
9586
*/
96-
export interface IOptions {
87+
export interface IOptions extends IDiffWidgetOptions {
9788
remote: any;
98-
cell: ICellModel;
99-
cellFooterTracker: ICellFooterTracker;
100-
originalSource: string;
101-
newSource?: string;
102-
showActionButtons?: boolean;
103-
openDiff?: boolean;
10489
}
10590
}

src/widget.ts

Lines changed: 9 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,16 @@ import { ICellModel } from '@jupyterlab/cells';
22
import { checkIcon, ToolbarButton, undoIcon } from '@jupyterlab/ui-components';
33
import { Widget } from '@lumino/widgets';
44
import { ICellFooterTracker } from 'jupyterlab-cell-input-footer';
5+
import { IDiffWidgetOptions } from './interfaces';
56

67
/**
78
* Base class for diff widgets with shared action button functionality
89
*/
910
export abstract class BaseDiffWidget extends Widget {
10-
protected _cell: ICellModel;
11-
protected _cellFooterTracker: ICellFooterTracker;
12-
protected _originalSource: string;
13-
protected _newSource: string;
14-
protected _showActionButtons: boolean;
15-
protected _openDiff: boolean;
16-
protected _toggleButton: ToolbarButton | null = null;
17-
1811
/**
1912
* Construct a new BaseDiffWidget.
2013
*/
21-
constructor(options: BaseDiffWidget.IOptions) {
14+
constructor(options: IDiffWidgetOptions) {
2215
super();
2316
this._cell = options.cell;
2417
this._cellFooterTracker = options.cellFooterTracker;
@@ -100,13 +93,11 @@ export abstract class BaseDiffWidget extends Widget {
10093
className: 'jp-DiffView-toggle',
10194
onClick: () => {
10295
this.onToggleClick();
103-
this._updateToggleButton();
10496
}
10597
});
10698

10799
footer.addToolbarItemOnLeft('toggle-diff', this._toggleButton);
108100

109-
// Only add action buttons if showActionButtons is true
110101
if (this._showActionButtons) {
111102
const rejectButton = new ToolbarButton({
112103
icon: undoIcon,
@@ -128,36 +119,11 @@ export abstract class BaseDiffWidget extends Widget {
128119
footer.addToolbarItemOnRight('accept-diff', acceptButton);
129120
}
130121

131-
// Show the diff view based on openDiff setting
132122
if (this._openDiff) {
133123
this.show();
134124
} else {
135125
this.hide();
136126
}
137-
this._updateToggleButton();
138-
}
139-
140-
/**
141-
* Update the toggle button label based on visibility
142-
*/
143-
private _updateToggleButton(): void {
144-
if (this._toggleButton) {
145-
// Remove and re-add with new label
146-
const footer = this._cellFooterTracker?.getFooter(this._cell?.id);
147-
if (footer) {
148-
footer.removeToolbarItem('toggle-diff');
149-
this._toggleButton = new ToolbarButton({
150-
label: 'Compare changes',
151-
enabled: true,
152-
className: 'jp-DiffView-toggle',
153-
onClick: () => {
154-
this.onToggleClick();
155-
this._updateToggleButton();
156-
}
157-
});
158-
footer.addToolbarItemOnLeft('toggle-diff', this._toggleButton);
159-
}
160-
}
161127
}
162128

163129
/**
@@ -177,21 +143,12 @@ export abstract class BaseDiffWidget extends Widget {
177143
this._cellFooterTracker.hideFooter(cellId);
178144
}
179145
}
180-
}
181146

182-
/**
183-
* A namespace for `BaseDiffWidget` statics.
184-
*/
185-
export namespace BaseDiffWidget {
186-
/**
187-
* The options used to construct a `BaseDiffWidget`.
188-
*/
189-
export interface IOptions {
190-
cell: ICellModel;
191-
cellFooterTracker: ICellFooterTracker;
192-
originalSource: string;
193-
newSource?: string;
194-
showActionButtons?: boolean;
195-
openDiff?: boolean;
196-
}
147+
protected _cell: ICellModel;
148+
protected _cellFooterTracker: ICellFooterTracker;
149+
protected _originalSource: string;
150+
protected _newSource: string;
151+
protected _showActionButtons: boolean;
152+
protected _openDiff: boolean;
153+
protected _toggleButton: ToolbarButton | null = null;
197154
}

0 commit comments

Comments
 (0)