Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,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)
Expand All @@ -127,6 +128,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

Expand Down
10 changes: 9 additions & 1 deletion src/diff/base-unified-diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export interface IBaseUnifiedDiffOptions {
* Whether to show accept/reject buttons
*/
showActionButtons?: boolean;

/**
* Whether to allow inline diffs
*/
allowInlineDiffs?: boolean;
}

/**
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
16 changes: 11 additions & 5 deletions src/diff/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -98,6 +96,11 @@ export interface IApplyDiffOptions {
* Optional callback when chunks are resolved
*/
onChunkChange?: () => void;

/**
* Whether to allow inline diffs
*/
allowInlineDiffs?: boolean;
}

/**
Expand All @@ -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 => {
Expand Down
18 changes: 17 additions & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
'Whether to show action buttons for chunk acceptance'
)
},
allowInlineDiffs: {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document that new argument in the README.md?

Also maybe we could also add it to the unified-file-diff command? (for file diffs)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's document that new argument in the README.md?

Yes we can :)

Also maybe we could also add it to the unified-file-diff command? (for file diffs)

Yes i also implemented it for unified-file-diff but cannot able to test it as the error comes No editor found for file so i removed the changes for unified-file-diff.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think unified-file-diff not supports notebook because it worked in .py file but not worked in .ipynb file.

type: 'boolean',
description: trans.__(
'Enable inline diffs (true) or disable (false)'
)
},
notebookPath: {
type: 'string',
description: trans.__('Path to the notebook containing the cell')
Expand All @@ -232,6 +238,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
originalSource,
newSource,
showActionButtons = true,
allowInlineDiffs = false,
notebookPath
} = args;

Expand Down Expand Up @@ -280,6 +287,7 @@ const unifiedCellDiffPlugin: JupyterFrontEndPlugin<void> = {
originalSource,
newSource,
showActionButtons,
allowInlineDiffs,
trans
});
cellDiffManagers.set(cell.id, manager);
Expand Down Expand Up @@ -333,6 +341,12 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin<void> = {
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']
Expand All @@ -343,7 +357,8 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin<void> = {
filePath,
originalSource,
newSource,
showActionButtons = true
showActionButtons = true,
allowInlineDiffs = false
} = args;

if (!originalSource || !newSource) {
Expand Down Expand Up @@ -399,6 +414,7 @@ const unifiedFileDiffPlugin: JupyterFrontEndPlugin<void> = {
originalSource,
newSource,
showActionButtons,
allowInlineDiffs,
trans
});
fileDiffManagers.set(managerKey, manager);
Expand Down
Loading