Skip to content

Commit 9834f09

Browse files
committed
fix(#228): Fixes issue where a single scroll event would cause multiple updates and calculate view placement incorrectly
1 parent fa30d27 commit 9834f09

1 file changed

Lines changed: 4 additions & 12 deletions

File tree

src/diff-view.js

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ CodeMirrorDiffView.prototype.scrollToDiff = function(direction) {
130130
this.trace('change', 'current-diff', this._current_diff);
131131
// _current_diff changed, refresh the view
132132
this._scroll_to_change(this.changes[this._current_diff]);
133-
this.setChanges(this.changes);
134133
};
135134

136135
CodeMirrorDiffView.prototype.mergeCurrentChange = function(side) {
@@ -149,7 +148,6 @@ CodeMirrorDiffView.prototype.scrollTo = function(side, num) {
149148
const ed = this.editor[side];
150149
ed.setCursor(num);
151150
ed.centerOnCursor();
152-
this._renderChanges();
153151
this.el.dispatchEvent(new Event('updated'));
154152
};
155153

@@ -556,20 +554,12 @@ CodeMirrorDiffView.prototype._scroll_to_change = function(change) {
556554
if (!change) {
557555
return;
558556
}
559-
const {
560-
lhs: led,
561-
rhs: red
562-
} = this.editor;
563-
// set cursors
564-
const llf = Math.max(change['lhs-line-from'], 0);
565-
const rlf = Math.max(change['rhs-line-from'], 0);
566-
led.setCursor(llf, 0);
567-
red.setCursor(rlf, 0);
568557
if (change['lhs-line-to'] >= 0) {
569558
this.scrollTo('lhs', change['lhs-line-to']);
570559
} else if (change['rhs-line-to'] >= 0) {
571560
this.scrollTo('rhs', change['rhs-line-to']);
572561
}
562+
const { lhs: led } = this.editor;
573563
led.focus();
574564
};
575565

@@ -1185,7 +1175,9 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
11851175
ctx_rhs.fillRect(1.5, rfrom, 4.5, rto);
11861176

11871177
this._handleLhsMarginClick = function (ev) {
1188-
const y = ev.pageY - ex.lhs_xyoffset.top - (lto / 2);
1178+
// `top` accounts for the editor starting at position other than 0 on page
1179+
const { top } = ev.currentTarget.offsetParent.getBoundingClientRect();
1180+
const y = (ev.pageY - top) - ex.lhs_xyoffset.top - (lto / 2);
11891181
const sto = Math.max(0, (y / mcanvas_lhs.height) * ex.lhs_scroller.scrollHeight);
11901182
ex.lhs_scroller.scrollTo({ top: sto });
11911183
};

0 commit comments

Comments
 (0)