Skip to content

Commit f410d0f

Browse files
committed
fix(#222): Right-hand editor gutter marker was not aligned correctly
fix(#222): Fixed poor rendering performance in large files
1 parent 3651df9 commit f410d0f

2 files changed

Lines changed: 19 additions & 12 deletions

File tree

src/diff-view.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,10 @@ CodeMirrorDiffView.prototype._isChangeInView = function(side, vp, change) {
740740
return true;
741741
}
742742

743+
// there are 3 conditions to test
744+
// 1: the change "from" is within the viewport from/to
745+
// 2: the change "to" is within the viewport from/to
746+
// 3: the change is so big that the viewport is within
743747
return (change[`${side}-line-from`] >= vp.from && change[`${side}-line-from`] <= vp.to) ||
744748
(change[`${side}-line-to`] >= vp.from && change[`${side}-line-to`] <= vp.to) ||
745749
(vp.from >= change[`${side}-line-from`] && vp.to <= change[`${side}-line-to`]);
@@ -1090,8 +1094,8 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
10901094
ctx_lhs.strokeRect(1.5, mkr_lhs_y_start, 4.5, Math.max(mkr_lhs_y_end - mkr_lhs_y_start, 5));
10911095
ctx_lhs.stroke();
10921096

1093-
const mkr_rhs_y_start = change['rhs-y-start'] * lratio;
1094-
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * lratio, 5);
1097+
const mkr_rhs_y_start = change['rhs-y-start'] * rratio;
1098+
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * rratio, 5);
10951099
ctx_rhs.beginPath();
10961100
ctx_rhs.fillStyle = '#a3a3a3';
10971101
ctx_rhs.strokeStyle = '#000';

src/vdoc.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,13 @@ class VDoc {
205205
if (this.options._debug) {
206206
trace('vdoc#update', side, editor, viewport);
207207
}
208-
const lines = Object.keys(this._lines[side]);
209-
for (let i = 0; i < lines.length; ++i) {
210-
const id = lines[i];
208+
const keys = Object.keys(this._lines[side]);
209+
// while Mergely diffs unicode diacritic chars (letters+mark),
210+
// CM is by character, so diffs need to be mapped.
211+
const mappedChars = mapLettersToChars(editor.getValue());
212+
213+
for (const key of keys) {
214+
const { id } = this._lines[side][key];
211215
if (id < viewport.from || id > viewport.to) {
212216
continue;
213217
}
@@ -216,7 +220,7 @@ class VDoc {
216220
if (vline.rendered) {
217221
continue;
218222
}
219-
vline.update(editor);
223+
vline.update(editor, mappedChars);
220224
}
221225
}
222226

@@ -257,7 +261,7 @@ class VLine {
257261
this.markup.push([ charFrom, charTo, className ]);
258262
}
259263

260-
update(editor) {
264+
update(editor, mappedChars) {
261265
if (this.rendered) {
262266
// FIXME: probably do not need this now
263267
console.log('already rendered', this.id);
@@ -279,18 +283,17 @@ class VLine {
279283
editor.setGutterMarker(this.id, name, item);
280284
}
281285
if (this.markup.length) {
282-
// while Mergely diffs unicode chars (letters+mark), CM is by character,
283-
// so diffs need to be mapped.
284-
const mapped = mapLettersToChars(editor.getValue());
286+
// while Mergely diffs unicode diacritic chars (letters+mark),
287+
// CM is by character, so diffs need to be mapped.
285288
for (const markup of this.markup) {
286289
const [ charFrom, charTo, className ] = markup;
287290
const fromPos = { line: this.id };
288291
const toPos = { line: this.id };
289292
if (charFrom >= 0) {
290-
fromPos.ch = mapped[charFrom];
293+
fromPos.ch = mappedChars[charFrom];
291294
}
292295
if (charTo >= 0) {
293-
toPos.ch = mapped[charTo];
296+
toPos.ch = mappedChars[charTo];
294297
}
295298
this._clearMarkup.push(
296299
editor.markText(fromPos, toPos, { className }));

0 commit comments

Comments
 (0)