Skip to content

Commit

Permalink
Line by line edits to ensure cursor doesnt move to end of chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Nov 23, 2017
1 parent 131d5e4 commit 89e1a18
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/diffUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,32 +101,21 @@ function parseUniDiffs(diffOutput: jsDiff.IUniDiff[]): FilePatch[] {
hunk.lines.forEach((line) => {
switch (line.substr(0, 1)) {
case '-':
if (edit == null) {
edit = new Edit(EditTypes.EDIT_DELETE, new Position(startLine - 1, 0));
}
edit = new Edit(EditTypes.EDIT_DELETE, new Position(startLine - 1, 0));
edit.end = new Position(startLine, 0);
edits.push(edit);
startLine++;
break;
case '+':
if (edit == null) {
edit = new Edit(EditTypes.EDIT_INSERT, new Position(startLine - 1, 0));
} else if (edit.action === EditTypes.EDIT_DELETE) {
edit.action = EditTypes.EDIT_REPLACE;
}
edit = new Edit(EditTypes.EDIT_INSERT, new Position(startLine - 1, 0));
edit.text += line.substr(1) + '\n';
edits.push(edit);
break;
case ' ':
startLine++;
if (edit != null) {
edits.push(edit);
}
edit = null;
break;
}
});
if (edit != null) {
edits.push(edit);
}
});

let fileName = uniDiff.oldFileName;
Expand Down

0 comments on commit 89e1a18

Please sign in to comment.