Skip to content

Commit eb15256

Browse files
committed
feat(merge): using undo after merges works
Fixes: #52 Fixes: #18
1 parent 6c1e819 commit eb15256

File tree

2 files changed

+26
-24
lines changed

2 files changed

+26
-24
lines changed

cypress/integration/merging.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,22 @@ describe('Merging code', () => {
6262
});
6363
});
6464
});
65+
66+
context('Undo is working', () => {
67+
before(() => {
68+
cy.visit('http://localhost:8081/test/fixtures/');
69+
cy.get('.acediff__deletedCodeConnector')
70+
.last()
71+
.click();
72+
});
73+
74+
it('allows me to undo merges', () => {
75+
cy.window().then((win) => {
76+
win.aceDiffer.getEditors().left.undo();
77+
const leftCode = JSON.parse(win.aceDiffer.getEditors().left.getValue());
78+
const rightCode = JSON.parse(win.aceDiffer.getEditors().right.getValue());
79+
expect(leftCode.keywords).to.not.deep.equal(rightCode.keywords);
80+
});
81+
});
82+
});
6583
});

src/index.js

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,13 @@ function addEventHandlers(acediff) {
298298
function copy(acediff, e, dir) {
299299
const diffIndex = parseInt(e.target.getAttribute('data-diff-index'), 10);
300300
const diff = acediff.diffs[diffIndex];
301-
let sourceEditor,
302-
targetEditor;
301+
let sourceEditor;
302+
let targetEditor;
303303

304-
let startLine,
305-
endLine,
306-
targetStartLine,
307-
targetEndLine;
304+
let startLine;
305+
let endLine;
306+
let targetStartLine;
307+
let targetEndLine;
308308
if (dir === C.LTR) {
309309
sourceEditor = acediff.editors.left;
310310
targetEditor = acediff.editors.right;
@@ -322,29 +322,13 @@ function copy(acediff, e, dir) {
322322
}
323323

324324
let contentToInsert = '';
325-
for (var i = startLine; i < endLine; i++) {
325+
for (let i = startLine; i < endLine; i += 1) {
326326
contentToInsert += `${getLine(sourceEditor, i)}\n`;
327327
}
328328

329-
let startContent = '';
330-
for (var i = 0; i < targetStartLine; i++) {
331-
startContent += `${getLine(targetEditor, i)}\n`;
332-
}
333-
334-
let endContent = '';
335-
const totalLines = targetEditor.ace.getSession().getLength();
336-
for (var i = targetEndLine; i < totalLines; i++) {
337-
endContent += getLine(targetEditor, i);
338-
if (i < totalLines - 1) {
339-
endContent += '\n';
340-
}
341-
}
342-
343-
endContent = endContent.replace(/\s*$/, '');
344-
345329
// keep track of the scroll height
346330
const h = targetEditor.ace.getSession().getScrollTop();
347-
targetEditor.ace.getSession().setValue(startContent + contentToInsert + endContent);
331+
targetEditor.ace.getSession().replace(new Range(targetStartLine, 0, targetEndLine, 0), contentToInsert);
348332
targetEditor.ace.getSession().setScrollTop(parseInt(h, 10));
349333

350334
acediff.diff();

0 commit comments

Comments
 (0)