Skip to content

Commit

Permalink
Support hiding base editor (#705)
Browse files Browse the repository at this point in the history
* Add ability to set showBase from CLI option

* Use DiffPanel for diff widgets

* Support merge view with 3 panels (theirs | final | ours) in addition to the current 4 panels views
Fixes #682

* Add integration tests

* Fix diff views

* Lint the code

* Fix final padding for merged editor in 3-panels view

* Fix scroll synchronization for 3-panels view

* Update Playwright Snapshots

* Update Playwright Snapshots

* Add delay to improve test robustness on Windows

* Change expectation

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
fcollonval and github-actions[bot] committed Oct 10, 2023
1 parent 40e692a commit 228b6b0
Show file tree
Hide file tree
Showing 21 changed files with 408 additions and 196 deletions.
7 changes: 7 additions & 0 deletions nbdime/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,12 @@ def add_merge_args(parser):
default=True,
help="disallow deletion of transient data such as outputs and "
"execution counts in order to resolve conflicts.")
parser.add_argument(
'--no-base',
dest='show_base',
action="store_false",
default=True,
help="Don't display the base version.")


filename_help = {
Expand Down Expand Up @@ -532,6 +538,7 @@ def args_for_server(arguments):
workdirectory='cwd',
base_url='base_url',
hide_unchanged='hide_unchanged',
show_base='show_base',
)
ret = {kmap[k]: v for k, v in vars(arguments).items() if k in kmap}
if 'persist' in arguments:
Expand Down
5 changes: 5 additions & 0 deletions nbdime/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,11 @@ class Merge(_Diffing):
"execution counts in order to resolve conflicts.",
).tag(config=True)

show_base = Bool(
True,
help="Whether to show the base version (4-panels) or not (3-panels).",
).tag(config=True)


class GitDiff(Diff):
use_filter = Bool(
Expand Down
3 changes: 3 additions & 0 deletions nbdime/webapp/nbdimeserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def get(self):
args['base'] = self.get_argument('base', '')
args['local'] = self.get_argument('local', '')
args['remote'] = self.get_argument('remote', '')
args['showBase'] = self.params.get('show_base', True)
self.write(self.render_template('merge.html',
config_data=args,
))
Expand All @@ -201,10 +202,12 @@ def get(self):
args['base'] = self.params['mergetool_args']['base']
args['local'] = self.params['mergetool_args']['local']
args['remote'] = self.params['mergetool_args']['remote']
args['showBase'] = self.params.get('show_base', True)
else:
args['base'] = self.get_argument('base', '')
args['local'] = self.get_argument('local', '')
args['remote'] = self.get_argument('remote', '')
args['showBase'] = self.params.get('show_base', True)
self.write(self.render_template('mergetool.html',
config_data=args,
))
Expand Down
36 changes: 36 additions & 0 deletions packages/nbdime/src/common/basepanel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) Jupyter Development Team.
// Distributed under the terms of the Modified BSD License.

import { Panel } from '@lumino/widgets';
import type { IDiffWidgetOptions, IMergeWidgetOptions } from './interfaces';
import type { CodeEditor } from '@jupyterlab/codeeditor';

/**
* Common panel for diff views
*/
export class DiffPanel<T> extends Panel {
constructor({ model, editorFactory }: IDiffWidgetOptions<T>) {
super();
this._editorFactory = editorFactory;
this._model = model;
}

protected _editorFactory: CodeEditor.Factory | undefined;
protected _model: T;
}

/**
* Common panel for merge views
*/
export class MergePanel<T> extends DiffPanel<T> {
constructor({
model,
editorFactory,
...viewOptions
}: IDiffWidgetOptions<T> & IMergeWidgetOptions) {
super({ model, editorFactory });
this._viewOptions = viewOptions;
}

protected _viewOptions: IMergeWidgetOptions;
}
17 changes: 16 additions & 1 deletion packages/nbdime/src/common/interfaces.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
import type { CodeEditor } from '@jupyterlab/codeeditor';
import type { IRenderMimeRegistry } from '@jupyterlab/rendermime';

/**
* Common merge view options
*/
export interface IMergeWidgetOptions {
/**
* Whether to show the base version (4-panels) or not (3-panels).
*/
showBase?: boolean;
}

/**
* Main widget constructor options
*/
// TODO `T` should be scoped down but more API rework will be needed on the model to achieve that
// there is definitely room to rationalize the code with more abstract or mixin classes.
export interface IDiffWidgetOptions<T> {
model: T;
editorFactory?: CodeEditor.Factory;
}

export interface IMimeDiffWidgetOptions<T> {
model: T;
rendermime: IRenderMimeRegistry;
editorFactory?: CodeEditor.Factory;
}

export interface ICellDiffWidgetOptions<T> extends IDiffWidgetOptions<T> {
export interface ICellDiffWidgetOptions<T> extends IMimeDiffWidgetOptions<T> {
// TODO this seems redundant as mimetype is part of the model
mimetype: string;
}

0 comments on commit 228b6b0

Please sign in to comment.