Skip to content

Commit

Permalink
Remove decision + picker when picking base on edit
Browse files Browse the repository at this point in the history
If you undo a manual edit by using the pickers, the decision should be
deleted unless there is a local/remote diff. If all decisions of a chunk
are removed, the picker should be removed as well.
  • Loading branch information
vidartf committed May 7, 2018
1 parent c49c68a commit 0d97fc9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
5 changes: 4 additions & 1 deletion packages/nbdime/src/chunking/diffchunking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
} from '../merge/decisions';

import {
valueIn, shallowCopy
valueIn, shallowCopy, unique
} from '../common/util';


Expand Down Expand Up @@ -166,6 +166,7 @@ class Chunker {
}
this.chunks.push(current);
}
current.sources = current.sources.filter(unique);
this.editOffset += isAddition ? -linediff : linediff;
}

Expand Down Expand Up @@ -222,6 +223,7 @@ class Chunker {
this.chunks.push(current);
}
this._currentGhost = current;
current.sources = current.sources.filter(unique);
// this._doAdd(range, isAddition);
}

Expand Down Expand Up @@ -285,6 +287,7 @@ function lineToNormalChunks(lineChunks: Chunk[]): Chunk[] {
current = shallowCopy(c);
}
}
current.sources = current.sources.filter(unique);
}
if (current !== null) {
ret.push(current);
Expand Down
32 changes: 27 additions & 5 deletions packages/nbdime/src/common/mergeview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
} from '../diff/model';

import {
DecisionStringDiffModel
DecisionStringDiffModel, CellMergeModel
} from '../merge/model';

import {
Expand All @@ -38,7 +38,7 @@ import {
} from './editor';

import {
valueIn, hasEntries, splitLines, copyObj
valueIn, hasEntries, splitLines, copyObj, removeElement
} from './util';

import {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion packages/nbdime/typings/codemirror.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 0d97fc9

Please sign in to comment.