From 4a8738f9f6f81e702bd8997ea197fc0898b6416a Mon Sep 17 00:00:00 2001 From: Nakul Date: Thu, 30 Oct 2025 11:48:09 +0530 Subject: [PATCH 1/3] Adding inlineDiffs for unified-cell diffs --- src/diff/base-unified-diff.ts | 10 +++++++++- src/diff/utils.ts | 16 +++++++++++----- src/plugin.ts | 8 ++++++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/diff/base-unified-diff.ts b/src/diff/base-unified-diff.ts index cd899a6..4ca6f6e 100644 --- a/src/diff/base-unified-diff.ts +++ b/src/diff/base-unified-diff.ts @@ -34,6 +34,11 @@ export interface IBaseUnifiedDiffOptions { * Whether to show accept/reject buttons */ showActionButtons?: boolean; + + /** + * Whether to allow inline diffs + */ + allowInlineDiffs?: boolean; } /** @@ -49,6 +54,7 @@ export abstract class BaseUnifiedDiffManager { this._newSource = options.newSource; this.trans = options.trans; this.showActionButtons = options.showActionButtons ?? true; + this.allowInlineDiffs = options.allowInlineDiffs ?? false; this._isInitialized = false; this._isDisposed = false; this._diffCompartment = new Compartment(); @@ -166,7 +172,8 @@ export abstract class BaseUnifiedDiffManager { newSource: this._newSource, isInitialized: this._isInitialized, sharedModel: this.getSharedModel(), - onChunkChange: () => this.deactivate() + onChunkChange: () => this.deactivate(), + allowInlineDiffs: this.allowInlineDiffs }); this._isInitialized = true; @@ -182,6 +189,7 @@ export abstract class BaseUnifiedDiffManager { protected editor: CodeMirrorEditor; protected trans: TranslationBundle; protected showActionButtons: boolean; + protected allowInlineDiffs: boolean; protected acceptAllButton: ToolbarButton | null = null; protected rejectAllButton: ToolbarButton | null = null; private _originalSource: string; diff --git a/src/diff/utils.ts b/src/diff/utils.ts index 61216f3..d237c3a 100644 --- a/src/diff/utils.ts +++ b/src/diff/utils.ts @@ -40,9 +40,7 @@ export function createMergeExtension( ): Extension { return unifiedMergeView({ original: originalSource, - ...options, - // TODO: make configurable - // allowInlineDiffs: true, + allowInlineDiffs: options?.allowInlineDiffs ?? false, mergeControls: ( type: 'accept' | 'reject', action: (e: MouseEvent) => void @@ -98,6 +96,11 @@ export interface IApplyDiffOptions { * Optional callback when chunks are resolved */ onChunkChange?: () => void; + + /** + * Whether to allow inline diffs + */ + allowInlineDiffs?: boolean; } /** @@ -111,10 +114,13 @@ export function applyDiff(options: IApplyDiffOptions): void { newSource, isInitialized, sharedModel, - onChunkChange + onChunkChange, + allowInlineDiffs = false } = options; - const mergeExtension = createMergeExtension(originalSource); + const mergeExtension = createMergeExtension(originalSource, { + allowInlineDiffs + }); // Create an update listener to track chunk resolution const updateListener = EditorView.updateListener.of(update => { diff --git a/src/plugin.ts b/src/plugin.ts index cc731c8..4f0b66f 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -218,6 +218,12 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin = { 'Whether to show action buttons for chunk acceptance' ) }, + allowInlineDiffs: { + type: 'boolean', + description: trans.__( + 'Enable inline diffs (true) or disable (false)' + ) + }, notebookPath: { type: 'string', description: trans.__('Path to the notebook containing the cell') @@ -232,6 +238,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin = { originalSource, newSource, showActionButtons = true, + allowInlineDiffs = false, notebookPath } = args; @@ -280,6 +287,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin = { originalSource, newSource, showActionButtons, + allowInlineDiffs, trans }); cellDiffManagers.set(cell.id, manager); From 4c17606da6189ca388febd6f752d1bde631afa06 Mon Sep 17 00:00:00 2001 From: Nakul Date: Thu, 30 Oct 2025 14:59:02 +0530 Subject: [PATCH 2/3] making `inlineDiffs` working with `unified-file-diff` and updating documentation. --- README.md | 8 ++++++-- src/plugin.ts | 10 +++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 813f8f2..77f9907 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,8 @@ app.commands.execute('jupyterlab-diff:unified-cell-diff', { cellId: 'cell-id', originalSource: 'print("Hello")', newSource: 'print("Hello, World!")', - showActionButtons: true + showActionButtons: true, + allowInlineDiffs: false }); ``` @@ -72,7 +73,8 @@ app.commands.execute('jupyterlab-diff:unified-file-diff', { filePath: '/path/to/file.py', originalSource: 'print("Hello")', newSource: 'print("Hello, World!")', - showActionButtons: true + showActionButtons: true, + allowInlineDiffs: false }); ``` @@ -117,6 +119,7 @@ window.jupyterapp.commands.execute('jupyterlab-diff:split-cell-diff', { | `originalSource` | `string` | Yes | Original source code to compare against | | `newSource` | `string` | Yes | New source code to compare with | | `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) | +| `allowInlineDiffs` | `boolean` | No | Whether to show inline diffs in the diff widget (default: `false`) | | `notebookPath` | `string` | No | Path to the notebook containing the cell. If not provided, uses the current notebook | #### `jupyterlab-diff:unified-file-diff` (File Diff) @@ -127,6 +130,7 @@ window.jupyterapp.commands.execute('jupyterlab-diff:split-cell-diff', { | `originalSource` | `string` | Yes | Original source code to compare against | | `newSource` | `string` | Yes | New source code to compare with | | `showActionButtons` | `boolean` | No | Whether to show action buttons for chunk acceptance (default: `true`) | +| `allowInlineDiffs` | `boolean` | No | Whether to show inline diffs in the diff widget (default: `false`) | ## Architecture diff --git a/src/plugin.ts b/src/plugin.ts index 4f0b66f..07d042e 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -341,6 +341,12 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin = { description: trans.__( 'Whether to show action buttons for chunk acceptance. Defaults to true.' ) + }, + allowInlineDiffs: { + type: 'boolean', + description: trans.__( + 'Enable inline diffs (true) or disable (false)' + ) } }, required: ['originalSource', 'newSource'] @@ -351,7 +357,8 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin = { filePath, originalSource, newSource, - showActionButtons = true + showActionButtons = true, + allowInlineDiffs = false } = args; if (!originalSource || !newSource) { @@ -407,6 +414,7 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin = { originalSource, newSource, showActionButtons, + allowInlineDiffs, trans }); fileDiffManagers.set(managerKey, manager); From 97611783fdf86f9e526026e44fbb7ee6f077edf4 Mon Sep 17 00:00:00 2001 From: Nakul Date: Thu, 30 Oct 2025 19:07:30 +0530 Subject: [PATCH 3/3] changes done --- README.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 77f9907..6b50819 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,7 @@ app.commands.execute('jupyterlab-diff:unified-cell-diff', { cellId: 'cell-id', originalSource: 'print("Hello")', newSource: 'print("Hello, World!")', - showActionButtons: true, - allowInlineDiffs: false + showActionButtons: true }); ``` @@ -73,8 +72,7 @@ app.commands.execute('jupyterlab-diff:unified-file-diff', { filePath: '/path/to/file.py', originalSource: 'print("Hello")', newSource: 'print("Hello, World!")', - showActionButtons: true, - allowInlineDiffs: false + showActionButtons: true }); ```