Skip to content

Commit

Permalink
[merge addon] Compensate for editor top offset when aligning lines
Browse files Browse the repository at this point in the history
Closes #6202
  • Loading branch information
marijnh committed Apr 2, 2020
1 parent e1d58e2 commit caca4ff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions addon/merge/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -443,22 +443,26 @@
aligners[i].clear();
aligners.length = 0;

var cm = [dv.edit, dv.orig], scroll = [];
var cm = [dv.edit, dv.orig], scroll = [], offset = []
if (other) cm.push(other.orig);
for (var i = 0; i < cm.length; i++)
for (var i = 0; i < cm.length; i++) {
scroll.push(cm[i].getScrollInfo().top);
offset.push(-cm[i].getScrollerElement().getBoundingClientRect().top)
}

if (offset[0] != offset[1] || cm.length == 3 && offset[1] != offset[2])
alignLines(cm, offset, [0, 0, 0], aligners)
for (var ln = 0; ln < linesToAlign.length; ln++)
alignLines(cm, linesToAlign[ln], aligners);
alignLines(cm, offset, linesToAlign[ln], aligners);

for (var i = 0; i < cm.length; i++)
cm[i].scrollTo(null, scroll[i]);
}

function alignLines(cm, lines, aligners) {
var maxOffset = 0, offset = [];
function alignLines(cm, cmOffset, lines, aligners) {
var maxOffset = -1e8, offset = [];
for (var i = 0; i < cm.length; i++) if (lines[i] != null) {
var off = cm[i].heightAtLine(lines[i], "local");
var off = cm[i].heightAtLine(lines[i], "local") - cmOffset[i];
offset[i] = off;
maxOffset = Math.max(maxOffset, off);
}
Expand Down

0 comments on commit caca4ff

Please sign in to comment.