diff --git a/packages/nbdime/src/chunking/diffchunking.ts b/packages/nbdime/src/chunking/diffchunking.ts index abb167dd..4e1f1530 100644 --- a/packages/nbdime/src/chunking/diffchunking.ts +++ b/packages/nbdime/src/chunking/diffchunking.ts @@ -16,7 +16,7 @@ import { } from '../merge/decisions'; import { - valueIn, shallowCopy + valueIn, shallowCopy, unique } from '../common/util'; @@ -166,6 +166,7 @@ class Chunker { } this.chunks.push(current); } + current.sources = current.sources.filter(unique); this.editOffset += isAddition ? -linediff : linediff; } @@ -222,6 +223,7 @@ class Chunker { this.chunks.push(current); } this._currentGhost = current; + current.sources = current.sources.filter(unique); // this._doAdd(range, isAddition); } @@ -285,6 +287,7 @@ function lineToNormalChunks(lineChunks: Chunk[]): Chunk[] { current = shallowCopy(c); } } + current.sources = current.sources.filter(unique); } if (current !== null) { ret.push(current); diff --git a/packages/nbdime/src/common/mergeview.ts b/packages/nbdime/src/common/mergeview.ts index 740d5e66..2cfbb596 100644 --- a/packages/nbdime/src/common/mergeview.ts +++ b/packages/nbdime/src/common/mergeview.ts @@ -22,7 +22,7 @@ import { } from '../diff/model'; import { - DecisionStringDiffModel + DecisionStringDiffModel, CellMergeModel } from '../merge/model'; import { @@ -38,7 +38,7 @@ import { } from './editor'; import { - valueIn, hasEntries, splitLines, copyObj + valueIn, hasEntries, splitLines, copyObj, removeElement } from './util'; import { @@ -433,14 +433,36 @@ class DiffView { for (let s of ss) { s.decision.action = s.action; } - } else if (instance === this.baseEditor) { + } else if (this.type === 'merge' && instance === this.baseEditor) { for (let s of ss) { s.decision.action = 'base'; - if (hasEntries(s.decision.customDiff)) { - s.decision.customDiff = []; + } + } + for (let i=ss.length - 1; i >= 0; --i) { + let s = ss[i]; + if (this.type === 'merge' && hasEntries(s.decision.customDiff)) { + // Custom diffs are cleared on pick, + // as there is no way to re-pick them + s.decision.customDiff = []; + // If decision is now empty, remove decision: + if (!hasEntries(s.decision.localDiff) && + !hasEntries(s.decision.remoteDiff)) { + // Remove decision: + let model = this.model as DecisionStringDiffModel; + let cell = model.parent as CellMergeModel; + removeElement(model.decisions, s.decision); + removeElement(cell.decisions, s.decision); + // Remove source + ss.splice(i, 1); } } } + if (ss.length === 0) { + // All decisions empty, remove picker + // In these cases, there should only be one picker, on base + // so simply remove the one we have here + instance.setGutterMarker(line, GUTTER_PICKER_CLASS, null); + } } else if (gutter === GUTTER_CONFLICT_CLASS) { for (let s of ss) { s.decision.conflict = false; diff --git a/packages/nbdime/typings/codemirror.d.ts b/packages/nbdime/typings/codemirror.d.ts index ea1d64ea..ff75e069 100644 --- a/packages/nbdime/typings/codemirror.d.ts +++ b/packages/nbdime/typings/codemirror.d.ts @@ -186,7 +186,7 @@ declare namespace CodeMirror { /** Sets the gutter marker for the given gutter (identified by its CSS class, see the gutters option) to the given value. Value can be either null, to clear the marker, or a DOM element, to set it. The DOM element will be shown in the specified gutter next to the specified line. */ - setGutterMarker(line: any, gutterID: string, value: HTMLElement | null): CodeMirror.LineHandle; + setGutterMarker(line: CodeMirror.LineHandle | number, gutterID: string, value: HTMLElement | null): CodeMirror.LineHandle; /** Remove all gutter markers in the gutter with the given ID. */ clearGutter(gutterID: string): void;