mirror of
https://github.com/wickedest/Mergely.git
synced 2026-03-24 09:48:39 +08:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f410d0f41a |
@@ -740,6 +740,10 @@ CodeMirrorDiffView.prototype._isChangeInView = function(side, vp, change) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// there are 3 conditions to test
|
||||||
|
// 1: the change "from" is within the viewport from/to
|
||||||
|
// 2: the change "to" is within the viewport from/to
|
||||||
|
// 3: the change is so big that the viewport is within
|
||||||
return (change[`${side}-line-from`] >= vp.from && change[`${side}-line-from`] <= vp.to) ||
|
return (change[`${side}-line-from`] >= vp.from && change[`${side}-line-from`] <= vp.to) ||
|
||||||
(change[`${side}-line-to`] >= vp.from && change[`${side}-line-to`] <= vp.to) ||
|
(change[`${side}-line-to`] >= vp.from && change[`${side}-line-to`] <= vp.to) ||
|
||||||
(vp.from >= change[`${side}-line-from`] && vp.to <= change[`${side}-line-to`]);
|
(vp.from >= change[`${side}-line-from`] && vp.to <= change[`${side}-line-to`]);
|
||||||
@@ -1090,8 +1094,8 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
|
|||||||
ctx_lhs.strokeRect(1.5, mkr_lhs_y_start, 4.5, Math.max(mkr_lhs_y_end - mkr_lhs_y_start, 5));
|
ctx_lhs.strokeRect(1.5, mkr_lhs_y_start, 4.5, Math.max(mkr_lhs_y_end - mkr_lhs_y_start, 5));
|
||||||
ctx_lhs.stroke();
|
ctx_lhs.stroke();
|
||||||
|
|
||||||
const mkr_rhs_y_start = change['rhs-y-start'] * lratio;
|
const mkr_rhs_y_start = change['rhs-y-start'] * rratio;
|
||||||
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * lratio, 5);
|
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * rratio, 5);
|
||||||
ctx_rhs.beginPath();
|
ctx_rhs.beginPath();
|
||||||
ctx_rhs.fillStyle = '#a3a3a3';
|
ctx_rhs.fillStyle = '#a3a3a3';
|
||||||
ctx_rhs.strokeStyle = '#000';
|
ctx_rhs.strokeStyle = '#000';
|
||||||
|
|||||||
23
src/vdoc.js
23
src/vdoc.js
@@ -205,9 +205,13 @@ class VDoc {
|
|||||||
if (this.options._debug) {
|
if (this.options._debug) {
|
||||||
trace('vdoc#update', side, editor, viewport);
|
trace('vdoc#update', side, editor, viewport);
|
||||||
}
|
}
|
||||||
const lines = Object.keys(this._lines[side]);
|
const keys = Object.keys(this._lines[side]);
|
||||||
for (let i = 0; i < lines.length; ++i) {
|
// while Mergely diffs unicode diacritic chars (letters+mark),
|
||||||
const id = lines[i];
|
// CM is by character, so diffs need to be mapped.
|
||||||
|
const mappedChars = mapLettersToChars(editor.getValue());
|
||||||
|
|
||||||
|
for (const key of keys) {
|
||||||
|
const { id } = this._lines[side][key];
|
||||||
if (id < viewport.from || id > viewport.to) {
|
if (id < viewport.from || id > viewport.to) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -216,7 +220,7 @@ class VDoc {
|
|||||||
if (vline.rendered) {
|
if (vline.rendered) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
vline.update(editor);
|
vline.update(editor, mappedChars);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -257,7 +261,7 @@ class VLine {
|
|||||||
this.markup.push([ charFrom, charTo, className ]);
|
this.markup.push([ charFrom, charTo, className ]);
|
||||||
}
|
}
|
||||||
|
|
||||||
update(editor) {
|
update(editor, mappedChars) {
|
||||||
if (this.rendered) {
|
if (this.rendered) {
|
||||||
// FIXME: probably do not need this now
|
// FIXME: probably do not need this now
|
||||||
console.log('already rendered', this.id);
|
console.log('already rendered', this.id);
|
||||||
@@ -279,18 +283,17 @@ class VLine {
|
|||||||
editor.setGutterMarker(this.id, name, item);
|
editor.setGutterMarker(this.id, name, item);
|
||||||
}
|
}
|
||||||
if (this.markup.length) {
|
if (this.markup.length) {
|
||||||
// while Mergely diffs unicode chars (letters+mark), CM is by character,
|
// while Mergely diffs unicode diacritic chars (letters+mark),
|
||||||
// so diffs need to be mapped.
|
// CM is by character, so diffs need to be mapped.
|
||||||
const mapped = mapLettersToChars(editor.getValue());
|
|
||||||
for (const markup of this.markup) {
|
for (const markup of this.markup) {
|
||||||
const [ charFrom, charTo, className ] = markup;
|
const [ charFrom, charTo, className ] = markup;
|
||||||
const fromPos = { line: this.id };
|
const fromPos = { line: this.id };
|
||||||
const toPos = { line: this.id };
|
const toPos = { line: this.id };
|
||||||
if (charFrom >= 0) {
|
if (charFrom >= 0) {
|
||||||
fromPos.ch = mapped[charFrom];
|
fromPos.ch = mappedChars[charFrom];
|
||||||
}
|
}
|
||||||
if (charTo >= 0) {
|
if (charTo >= 0) {
|
||||||
toPos.ch = mapped[charTo];
|
toPos.ch = mappedChars[charTo];
|
||||||
}
|
}
|
||||||
this._clearMarkup.push(
|
this._clearMarkup.push(
|
||||||
editor.markText(fromPos, toPos, { className }));
|
editor.markText(fromPos, toPos, { className }));
|
||||||
|
|||||||
Reference in New Issue
Block a user