1
0
mirror of synced 2025-12-14 10:28:11 +08:00

Compare commits

...

2 Commits
4.3.3 ... 4.3.5

Author SHA1 Message Date
Jamie Peabody
623a93b838 fix build 2021-10-03 16:56:35 +01:00
Jamie Peabody
615e1afd97 patch(#139): fixes inline diff rendering issue with whitespace (#158)
Co-authored-by: Jamie Peabody <jpeabody@axway.com>
2021-10-03 16:49:44 +01:00
4 changed files with 99 additions and 33 deletions

View File

@@ -1,5 +1,11 @@
# Changes # Changes
## 4.3.5
* patch: fixed issue with build
## 4.3.4
* patch: Fixes inline diff rendering issue with whitespace [#139](https://github.com/wickedest/Mergely/issues/139).
## 4.3.3 ## 4.3.3
* patch: Fixes resize issue when using zoom [#152](https://github.com/wickedest/Mergely/issues/152). * patch: Fixes resize issue when using zoom [#152](https://github.com/wickedest/Mergely/issues/152).

View File

@@ -2,18 +2,29 @@ require('codemirror/addon/selection/mark-selection.js');
require('codemirror/lib/codemirror.css'); require('codemirror/lib/codemirror.css');
require('../src/mergely.css'); require('../src/mergely.css');
var lhs = `\
the quick red fox
jumped over the hairy dog
`;
var rhs = `\
the quick brown fox
jumped over the lazy dog
`;
$(document).ready(function () { $(document).ready(function () {
$('#mergely').mergely({ $('#mergely').mergely({
license: 'lgpl', license: 'lgpl',
ignorews: true,
cmsettings: { cmsettings: {
readOnly: false readOnly: false
}, },
_debug: '', _debug: '',
lhs: function(setValue) { lhs: function(setValue) {
setValue('the quick red fox\njumped over the hairy dog'); setValue(lhs);
}, },
rhs: function(setValue) { rhs: function(setValue) {
setValue('the quick brown fox\njumped over the lazy dog'); setValue(rhs);
} }
}); });
}); });

View File

@@ -1,6 +1,6 @@
{ {
"name": "mergely", "name": "mergely",
"version": "4.3.3", "version": "4.3.5",
"description": "A javascript UI for diff/merge", "description": "A javascript UI for diff/merge",
"directories": { "directories": {
"doc": "doc", "doc": "doc",

View File

@@ -42,45 +42,85 @@ Mgly.sizeOf = function(obj) {
}; };
Mgly.LCS = function(x, y, options) { Mgly.LCS = function(x, y, options) {
this.x = (x && x.replace(/[ ]{1}/g, '\n')) || ''; function getPositionOfWords(text, options) {
this.y = (y && y.replace(/[ ]{1}/g, '\n')) || ''; var exp = new RegExp(/\w+/g);
var map = {};
var match;
var item = 0;
var p0 = 0;
var p1;
var ws0;
while ((match = exp.exec(text))) {
// if previous ws, then calculate whether not not this should be
// included as part of the diff
if (!options.ignorews && ws0 && ws0 <= match.index - 1) {
map[ item++ ] = {
p0: ws0,
p1: match.index - 1,
ws0,
word: text.slice(ws0, match.index)
};
}
// add the words to be matched in diff
p0 = match.index;
p1 = p0 + match[0].length - 1;
ws0 = p1 + 2;
map[ item++ ] = {
p0,
p1,
ws0,
word: text.slice(p0, p1 + 1)
};
}
return map;
}
this.options = options; this.options = options;
if (options.ignorews) {
this.xmap = getPositionOfWords(x, this.options);
this.ymap = getPositionOfWords(y, this.options);
var xmap = this.xmap;
this.x = Object.keys(xmap).map(function (i) { return xmap[i].word; });
var ymap = this.ymap;
this.y = Object.keys(ymap).map(function (i) { return ymap[i].word; });
} else {
this.x = x.split('');
this.y = y.split('');
}
}; };
jQuery.extend(Mgly.LCS.prototype, { jQuery.extend(Mgly.LCS.prototype, {
clear: function() { this.ready = 0; }, clear: function() { this.ready = 0; },
diff: function(added, removed) { diff: function(added, removed) {
var d = new Mgly.diff(this.x, this.y, { var d = new Mgly.diff(this.x, this.y, {
ignorews: false, ignorews: !!this.options.ignorews,
ignoreaccents: !!this.options.ignoreaccents ignoreaccents: !!this.options.ignoreaccents
}); });
var changes = Mgly.DiffParser(d.normal_form()); var changes = Mgly.DiffParser(d.normal_form());
var li = 0, lj = 0;
for (var i = 0; i < changes.length; ++i) { for (var i = 0; i < changes.length; ++i) {
var change = changes[i]; var change = changes[i];
if (change.op != 'a') { if (this.options.ignorews) {
// find the starting index of the line if (change.op != 'a') {
li = d.getLines('lhs').slice(0, change['lhs-line-from']).join(' ').length; var from = this.xmap[change['lhs-line-from']].p0;
// get the index of the the span of the change var to = this.xmap[change['lhs-line-to']].p1 + 1;
lj = change['lhs-line-to'] + 1; removed(from, to);
// get the changed text }
var lchange = d.getLines('lhs').slice(change['lhs-line-from'], lj).join(' '); if (change.op !== 'd') {
if (change.op == 'd') lchange += ' ';// include the leading space var from = this.ymap[change['rhs-line-from']].p0;
else if (li > 0 && change.op == 'c') li += 1; // ignore leading space if not first word var to = this.ymap[change['rhs-line-to']].p1 + 1;
// output the changed index and text added(from, to);
removed(li, li + lchange.length); }
} } else {
if (change.op != 'd') { if (change.op != 'a') {
// find the starting index of the line var from = change['lhs-line-from'];
li = d.getLines('rhs').slice(0, change['rhs-line-from']).join(' ').length; var to = change['lhs-line-to'] + 1;
// get the index of the the span of the change removed(from, to);
lj = change['rhs-line-to'] + 1; }
// get the changed text if (change.op !== 'd') {
var rchange = d.getLines('rhs').slice(change['rhs-line-from'], lj).join(' '); var from = change['rhs-line-from'];
if (change.op == 'a') rchange += ' ';// include the leading space var to = change['rhs-line-to'] + 1;
else if (li > 0 && change.op == 'c') li += 1; // ignore leading space if not first word added(from, to);
// output the changed index and text }
added(li, li + rchange.length);
} }
} }
} }
@@ -91,8 +131,16 @@ Mgly.CodeifyText = function(settings) {
this._diff_codes = {}; this._diff_codes = {};
this.ctxs = {}; this.ctxs = {};
jQuery.extend(this, settings); jQuery.extend(this, settings);
this.lhs = settings.lhs.split('\n'); if (typeof settings.lhs === 'string') {
this.rhs = settings.rhs.split('\n'); this.lhs = settings.lhs.split('\n');
} else {
this.lhs = settings.lhs;
}
if (typeof settings.rhs === 'string') {
this.rhs = settings.rhs.split('\n');
} else {
this.rhs = settings.rhs;
}
}; };
jQuery.extend(Mgly.CodeifyText.prototype, { jQuery.extend(Mgly.CodeifyText.prototype, {
@@ -1431,7 +1479,8 @@ jQuery.extend(Mgly.CodeMirrorDiffView.prototype, {
lhs_line = led.getLine( j ); lhs_line = led.getLine( j );
rhs_line = red.getLine( k ); rhs_line = red.getLine( k );
var lcs = new Mgly.LCS(lhs_line, rhs_line, { var lcs = new Mgly.LCS(lhs_line, rhs_line, {
ignoreaccents: !!this.settings.ignoreaccents ignoreaccents: !!this.settings.ignoreaccents,
ignorews: !!this.settings.ignorews
}); });
lcs.diff( lcs.diff(
function added (from, to) { function added (from, to) {