Skip to content

Commit 4a8738f

Browse files
committed
Adding inlineDiffs for unified-cell diffs
1 parent b5cf575 commit 4a8738f

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/diff/base-unified-diff.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ export interface IBaseUnifiedDiffOptions {
3434
* Whether to show accept/reject buttons
3535
*/
3636
showActionButtons?: boolean;
37+
38+
/**
39+
* Whether to allow inline diffs
40+
*/
41+
allowInlineDiffs?: boolean;
3742
}
3843

3944
/**
@@ -49,6 +54,7 @@ export abstract class BaseUnifiedDiffManager {
4954
this._newSource = options.newSource;
5055
this.trans = options.trans;
5156
this.showActionButtons = options.showActionButtons ?? true;
57+
this.allowInlineDiffs = options.allowInlineDiffs ?? false;
5258
this._isInitialized = false;
5359
this._isDisposed = false;
5460
this._diffCompartment = new Compartment();
@@ -166,7 +172,8 @@ export abstract class BaseUnifiedDiffManager {
166172
newSource: this._newSource,
167173
isInitialized: this._isInitialized,
168174
sharedModel: this.getSharedModel(),
169-
onChunkChange: () => this.deactivate()
175+
onChunkChange: () => this.deactivate(),
176+
allowInlineDiffs: this.allowInlineDiffs
170177
});
171178

172179
this._isInitialized = true;
@@ -182,6 +189,7 @@ export abstract class BaseUnifiedDiffManager {
182189
protected editor: CodeMirrorEditor;
183190
protected trans: TranslationBundle;
184191
protected showActionButtons: boolean;
192+
protected allowInlineDiffs: boolean;
185193
protected acceptAllButton: ToolbarButton | null = null;
186194
protected rejectAllButton: ToolbarButton | null = null;
187195
private _originalSource: string;

src/diff/utils.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ export function createMergeExtension(
4040
): Extension {
4141
return unifiedMergeView({
4242
original: originalSource,
43-
...options,
44-
// TODO: make configurable
45-
// allowInlineDiffs: true,
43+
allowInlineDiffs: options?.allowInlineDiffs ?? false,
4644
mergeControls: (
4745
type: 'accept' | 'reject',
4846
action: (e: MouseEvent) => void
@@ -98,6 +96,11 @@ export interface IApplyDiffOptions {
9896
* Optional callback when chunks are resolved
9997
*/
10098
onChunkChange?: () => void;
99+
100+
/**
101+
* Whether to allow inline diffs
102+
*/
103+
allowInlineDiffs?: boolean;
101104
}
102105

103106
/**
@@ -111,10 +114,13 @@ export function applyDiff(options: IApplyDiffOptions): void {
111114
newSource,
112115
isInitialized,
113116
sharedModel,
114-
onChunkChange
117+
onChunkChange,
118+
allowInlineDiffs = false
115119
} = options;
116120

117-
const mergeExtension = createMergeExtension(originalSource);
121+
const mergeExtension = createMergeExtension(originalSource, {
122+
allowInlineDiffs
123+
});
118124

119125
// Create an update listener to track chunk resolution
120126
const updateListener = EditorView.updateListener.of(update => {

src/plugin.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,12 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
218218
'Whether to show action buttons for chunk acceptance'
219219
)
220220
},
221+
allowInlineDiffs: {
222+
type: 'boolean',
223+
description: trans.__(
224+
'Enable inline diffs (true) or disable (false)'
225+
)
226+
},
221227
notebookPath: {
222228
type: 'string',
223229
description: trans.__('Path to the notebook containing the cell')
@@ -232,6 +238,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
232238
originalSource,
233239
newSource,
234240
showActionButtons = true,
241+
allowInlineDiffs = false,
235242
notebookPath
236243
} = args;
237244

@@ -280,6 +287,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
280287
originalSource,
281288
newSource,
282289
showActionButtons,
290+
allowInlineDiffs,
283291
trans
284292
});
285293
cellDiffManagers.set(cell.id, manager);

0 commit comments

Comments
 (0)