chore: fixed issue with lcs

This commit is contained in:
Jamie Peabody
2022-01-15 16:38:52 +00:00
parent d6c726d333
commit 3d06333dfc
4 changed files with 9 additions and 11 deletions

View File

@@ -33,10 +33,11 @@ document.onreadystatechange = function () {
},
rhs: function(setValue) {
setValue(macbeth.join('\n')
.replace(/serpent/g, 'pencil'));
.replace(/\brain\b/g, 'sleet')
.replace(/\bfog\b/g, 'smog'));
//.replace(/heart/g, 'head'));
},
_debug: 'scroll,debug,event'
_debug: ''
// _debug: 'draw,change,event'
});

View File

@@ -668,11 +668,9 @@ CodeMirrorDiffView.prototype.bind = function(el) {
if (this._current_diff >= 0) {
const current = this.changes[this._current_diff];
for (let i = current['lhs-line-from']; i <= current['lhs-line-to']; ++i) {
console.log('remove gutter lhs', i);
this.editor.lhs.removeLineClass(i, 'gutter');
}
for (let i = current['rhs-line-from']; i <= current['rhs-line-to']; ++i) {
console.log('remove gutter rhs', i);
this.editor.rhs.removeLineClass(i, 'gutter');
}
}
@@ -1204,7 +1202,9 @@ CodeMirrorDiffView.prototype._markupLineChanges = function (changes) {
});
}
if (lineDiff && (lhsInView || rhsInView)) {
if (lineDiff
&& (lhsInView || rhsInView)
&& change.op === 'c') {
vdoc.addInlineDiff(change, {
getText: (side, lineNum) => {
if (side === 'lhs') {

View File

@@ -59,7 +59,6 @@ LCS.prototype.diff = function (added, removed) {
ignoreaccents: !!this.options.ignoreaccents
});
const changes = DiffParser(d.normal_form());
console.log(changes);
for (let i = 0; i < changes.length; ++i) {
const change = changes[i];
if (this.options.ignorews) {

View File

@@ -54,7 +54,7 @@ class VDoc {
// FIXME: need lineDiff here?
} else {
// apply change for each line in-between the changed lines
for (let j = lf; j <= lt; ++j) {
for (let j = lf, k = olf; j <= lt; ++j, ++k) {
this._getLine(side, j).addLineClass('background', bgClass.join(' '));
if (!lineDiff) {
@@ -64,7 +64,7 @@ class VDoc {
if (side === 'lhs'
&& (change.op === 'd'
|| (change.op === 'c' && j > olt)
|| (change.op === 'c' && k > olt)
)) {
// mark entire line text with deleted (strikeout) if the
// change is a delete, or if it is changed text and the
@@ -72,7 +72,7 @@ class VDoc {
this._getLine(side, j).markText(0, undefined, 'mergely ch d lhs');
} else if (side == 'rhs'
&& (change.op === 'a'
|| (change.op === 'c' && j > olt)
|| (change.op === 'c' && k > olt)
)) {
// mark entire line text with added if the change is an
// add, or if it is changed text and the line goes past the
@@ -116,12 +116,10 @@ class VDoc {
// too many lines here. it's no more than the viewport.
lcs.diff(
function _added(from, to) {
console.log('added', {from, to});
const line = vdoc._getLine('rhs', k);
line.markText(from, to, 'mergely ch a rhs');
},
function _removed(from, to) {
console.log('removed', {from, to});
const line = vdoc._getLine('lhs', j);
line.markText(from, to, 'mergely ch d lhs');
}