Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicate pickers #735

Merged
merged 10 commits into from
Nov 10, 2023
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
3 changes: 2 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
**/.ipynb_checkpoints
**/coverage
CHANGELOG.md
package-lock.json
package-lock.json
nbdime/tests/files/inline-conflict--decisions.json
39 changes: 25 additions & 14 deletions packages/nbdime/src/common/mergeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,21 +295,21 @@
class MergeMarker extends GutterMarker {
constructor(options: { symbol: string; className: string; block: boolean }) {
super();
this._symbol = options.symbol;
this._className = options.className;
this._block = options.block;
}
get isBlock() {
return this._block;
this.symbol = options.symbol;
this.className = options.className;
this.block = options.block;
}
toDOM() {
let pickerMarker = elt('div', this._symbol);
pickerMarker.className = this._className;
let pickerMarker = elt('div', this.symbol);
pickerMarker.className = this.className;
return pickerMarker;
}
private _symbol: string;
private _className: string;
private _block: boolean;
eq(other: GutterMarker): boolean {
return other === this;

Check warning on line 308 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L307-L308

Added lines #L307 - L308 were not covered by tests
krassowski marked this conversation as resolved.
Show resolved Hide resolved
}
readonly symbol: string;
readonly className: string;
readonly block: boolean;
}

/**
Expand All @@ -332,7 +332,18 @@
: e.value.block
? conflictBlockMarker
: conflictMarker;
gutters = gutters.update({ add: [marker.range(e.value.from)] });
// check for overlap (duplicates) with same type
let overlap = false;
gutters.between(e.value.from, e.value.from, (from, to, value) => {

Check warning on line 337 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L336-L337

Added lines #L336 - L337 were not covered by tests
if (from === e.value.from && value.eq(marker)) {
overlap = true;
return false;

Check warning on line 340 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L339-L340

Added lines #L339 - L340 were not covered by tests
}
return;

Check warning on line 342 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L342

Added line #L342 was not covered by tests
});
if (!overlap) {
gutters = gutters.update({ add: [marker.range(e.value.from)] });

Check warning on line 345 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L345

Added line #L345 was not covered by tests
}
}
}
if (e.is(removeGutterMarkerEffect)) {
Expand Down Expand Up @@ -1417,7 +1428,7 @@
class: 'cm-gutter',
markers: view => {
return view.state.field(gutterMarkerField).update({
filter: (_from, _to, value: MergeMarker) => !value.isBlock,
filter: (_from, _to, value: MergeMarker) => !value.block,

Check warning on line 1431 in packages/nbdime/src/common/mergeview.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/common/mergeview.ts#L1431

Added line #L1431 was not covered by tests
});
},
widgetMarker: (
Expand All @@ -1430,7 +1441,7 @@
}
const markers = view.state.field(gutterMarkerField).update({
filter: (from, _to, value: MergeMarker) =>
value.isBlock && block.from === from,
value.block && block.from === from,
});
if (markers.size > 1) {
throw Error('More than one block gutter widget matched');
Expand Down
7 changes: 6 additions & 1 deletion packages/nbdime/src/merge/model/cell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,12 @@
*/
get agreedCell(): boolean {
// TODO: Also check other fields?
return this.agreedSource && this.agreedMetadata && this.agreedOutputs && this.agreedIds;
return (
this.agreedSource &&
this.agreedMetadata &&
this.agreedOutputs &&
this.agreedIds

Check warning on line 276 in packages/nbdime/src/merge/model/cell.ts

View check run for this annotation

Codecov / codecov/patch

packages/nbdime/src/merge/model/cell.ts#L274-L276

Added lines #L274 - L276 were not covered by tests
);
}

/**
Expand Down
14 changes: 7 additions & 7 deletions packages/nbdime/src/styles/merge.css
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@
.cm-merge-m-chunk-end-either-empty::after
+ .cm-linewidget
.cm-merge-spacer {
content: '';
width: 100%;
height: 1px;
background: var(--jp-merge-either-color1);
display: block;
position: absolute;
left: 0px;
content: '';
width: 100%;
height: 1px;
background: var(--jp-merge-either-color1);
display: block;
position: absolute;
left: 0px;
}

.jp-Notebook-merge .cm-central-editor .cm-line .cm-merge-m-deleted,
Expand Down
37 changes: 20 additions & 17 deletions packages/webapp/src/app/merge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,23 +183,26 @@ function onPopState(e: PopStateEvent) {
*/
function onMergeRequestCompleted(data: any) {
let layoutWork = showMerge(data);
layoutWork.then(() => {
toggleSpinner(false);
markUnchangedRanges();
}, reason => {
console.log("Failed to show merge result");
let root = document.getElementById('nbdime-root');
if (!root) {
throw new Error('Missing root element "nbidme-root"');
}
const pre = document.createElement('pre');
pre.innerText = reason || "Error occurred displaying merge!";
pre.classList.add("jp-mergeapp-error");
// we might have a partial render, so leave that in case it is useful
root.prepend(pre);
mergeWidget = null;
toggleSpinner(false);
});
layoutWork.then(
() => {
toggleSpinner(false);
markUnchangedRanges();
},
reason => {
console.log('Failed to show merge result');
let root = document.getElementById('nbdime-root');
if (!root) {
throw new Error('Missing root element "nbidme-root"');
}
const pre = document.createElement('pre');
pre.innerText = reason || 'Error occurred displaying merge!';
pre.classList.add('jp-mergeapp-error');
// we might have a partial render, so leave that in case it is useful
root.prepend(pre);
mergeWidget = null;
toggleSpinner(false);
},
);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions ui-tests/tests/nbdime-merge-test1.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.describe('merge test1', () => {
});

test('take a snapshot at opening', async ({ page }) => {
await expect.soft(page.getByText('➭')).toHaveCount(12);
await expect.soft(page.getByText('➭')).toHaveCount(11);

await expect.soft(page.locator('#nbdime-header-base')).toHaveText('Base');

Expand Down Expand Up @@ -40,7 +40,7 @@ test.describe('merge test1', () => {
.locator('.cm-central-editor')
.nth(1) // This select the cell; 0 being the notebook metadata
.locator('.jp-Merge-gutter-picker')
.nth(2)
.nth(1)
.click();
await page.getByText('⚠').click();
expect(await page.locator('#main').screenshot()).toMatchSnapshot();
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions ui-tests/tests/nbdime-merge-test2.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(async ({ page }) => {
/* notebooks of same length with 0 conflict*/
test.describe('merge test2 ', () => {
test('take a snapshot at opening', async ({ page }) => {
await expect.soft(page.getByText('➭')).toHaveCount(12);
await expect.soft(page.getByText('➭')).toHaveCount(11);
expect(await page.locator('#main').screenshot()).toMatchSnapshot();
});

Expand All @@ -30,7 +30,7 @@ test.describe('merge test2 ', () => {
.locator('.cm-central-editor')
.nth(1) // This select the cell; 0 being the notebook metadata
.locator('.jp-Merge-gutter-picker')
.nth(2)
.nth(1)
.click();
expect(await page.locator('#main').screenshot()).toMatchSnapshot();
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion ui-tests/tests/nbdime-merge-test3.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ test.beforeEach(async ({ page }) => {
/* 2 cells with merge conflict */
test.describe('merge test3', () => {
test('should warn for remaining conflicts', async ({ page }) => {
await expect.soft(page.getByText('➭')).toHaveCount(26);
await expect.soft(page.getByText('➭')).toHaveCount(25);

await page.getByRole('button', { name: 'Download' }).click();

Expand Down
Loading