Compare commits
3 Commits
v5.0.0-alp
...
v5.0.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37fedd05c8 | ||
|
|
f3e90b7588 | ||
|
|
650daaff63 |
5
.github/workflows/branch.yaml
vendored
5
.github/workflows/branch.yaml
vendored
@@ -3,7 +3,10 @@ name: Run tests (branch)
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches-ignore:
|
branches-ignore:
|
||||||
- 'master'
|
- master
|
||||||
|
- alpha
|
||||||
|
- beta
|
||||||
|
- next
|
||||||
tags-ignore:
|
tags-ignore:
|
||||||
- 'v*'
|
- 'v*'
|
||||||
|
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "mergely",
|
"name": "mergely",
|
||||||
"version": "5.0.0-rc0",
|
"version": "5.0.0-alpha.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mergely",
|
"name": "mergely",
|
||||||
"version": "5.0.0-rc0",
|
"version": "5.0.0-alpha.2",
|
||||||
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
|
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.1.6",
|
"@babel/core": "^7.1.6",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mergely",
|
"name": "mergely",
|
||||||
"version": "5.0.0-rc0",
|
"version": "5.0.0-alpha.2",
|
||||||
"description": "A javascript UI for diff/merge",
|
"description": "A javascript UI for diff/merge",
|
||||||
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
|
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
|
||||||
"author": {
|
"author": {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ CodeMirrorDiffView.prototype.init = function(el, options = {}) {
|
|||||||
lineNumbers: this.settings.line_numbers,
|
lineNumbers: this.settings.line_numbers,
|
||||||
gutters: (this.settings.line_numbers && [ 'merge', 'CodeMirror-linenumbers' ]) || [],
|
gutters: (this.settings.line_numbers && [ 'merge', 'CodeMirror-linenumbers' ]) || [],
|
||||||
};
|
};
|
||||||
this._vdoc = new VDoc();
|
this._vdoc = new VDoc({ _debug: this.settings._debug });
|
||||||
};
|
};
|
||||||
|
|
||||||
CodeMirrorDiffView.prototype.unbind = function() {
|
CodeMirrorDiffView.prototype.unbind = function() {
|
||||||
@@ -290,11 +290,6 @@ CodeMirrorDiffView.prototype.bind = function(container) {
|
|||||||
className: container.className
|
className: container.className
|
||||||
};
|
};
|
||||||
const el = dom.getMergelyContainer({ clazz: container.className });
|
const el = dom.getMergelyContainer({ clazz: container.className });
|
||||||
// const found = document.getElementById(container.id);
|
|
||||||
// if (!found) {
|
|
||||||
// console.error(`Failed to find mergely: #${container.id}`);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
const computedStyle = window.getComputedStyle(container);
|
const computedStyle = window.getComputedStyle(container);
|
||||||
if (!computedStyle.height || computedStyle.height === '0px') {
|
if (!computedStyle.height || computedStyle.height === '0px') {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
@@ -440,7 +435,10 @@ CodeMirrorDiffView.prototype.bind = function(container) {
|
|||||||
trace('event#lhs-scroll');
|
trace('event#lhs-scroll');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._scrolling({ side: 'lhs' });
|
// firefox scroll-linked effect render issue
|
||||||
|
setTimeout(() => {
|
||||||
|
this._scrolling({ side: 'lhs' });
|
||||||
|
}, 1);
|
||||||
});
|
});
|
||||||
this.editor.rhs.on('change', (instance, ev) => {
|
this.editor.rhs.on('change', (instance, ev) => {
|
||||||
if (this.settings._debug) {
|
if (this.settings._debug) {
|
||||||
@@ -459,7 +457,10 @@ CodeMirrorDiffView.prototype.bind = function(container) {
|
|||||||
trace('event#rhs-scroll');
|
trace('event#rhs-scroll');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this._scrolling({ side: 'rhs' });
|
// firefox scroll-linked effect render issue
|
||||||
|
setTimeout(() => {
|
||||||
|
this._scrolling({ side: 'rhs' });
|
||||||
|
}, 1);
|
||||||
});
|
});
|
||||||
|
|
||||||
// resize event handeler
|
// resize event handeler
|
||||||
@@ -560,7 +561,7 @@ CodeMirrorDiffView.prototype._clearMarkup = function () {
|
|||||||
traceTimeStart('draw#_clearMarkup');
|
traceTimeStart('draw#_clearMarkup');
|
||||||
}
|
}
|
||||||
this._vdoc.clear();
|
this._vdoc.clear();
|
||||||
this._vdoc = new VDoc();
|
this._vdoc = new VDoc({ _debug: this.settings._debug });
|
||||||
if (this.settings._debug) {
|
if (this.settings._debug) {
|
||||||
traceTimeEnd('draw#_clearMarkup');
|
traceTimeEnd('draw#_clearMarkup');
|
||||||
}
|
}
|
||||||
@@ -634,7 +635,10 @@ CodeMirrorDiffView.prototype._scrolling = function({ side }) {
|
|||||||
const scroller = this.editor[side].getScrollerElement();
|
const scroller = this.editor[side].getScrollerElement();
|
||||||
const { top } = scroller.getBoundingClientRect();
|
const { top } = scroller.getBoundingClientRect();
|
||||||
let height;
|
let height;
|
||||||
if (true || this.midway == undefined) {
|
if (scroller.offsetParent === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.midway == undefined) {
|
||||||
height = scroller.clientHeight
|
height = scroller.clientHeight
|
||||||
- (scroller.offsetHeight - scroller.offsetParent.offsetHeight);
|
- (scroller.offsetHeight - scroller.offsetParent.offsetHeight);
|
||||||
this.midway = (height / 2.0 + top).toFixed(2);
|
this.midway = (height / 2.0 + top).toFixed(2);
|
||||||
@@ -991,14 +995,10 @@ CodeMirrorDiffView.prototype._markupLineChanges = function (changes) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
led.operation(() => {
|
led.operation(() => {
|
||||||
for (let i = 0; i < changes.length; ++i) {
|
vdoc.update('lhs', led, lhsvp);
|
||||||
vdoc.update('lhs', i, led, lhsvp);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
red.operation(() => {
|
red.operation(() => {
|
||||||
for (let i = 0; i < changes.length; ++i) {
|
vdoc.update('rhs', red, rhsvp);
|
||||||
vdoc.update('rhs', i, red, rhsvp);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
if (this.settings._debug) {
|
if (this.settings._debug) {
|
||||||
traceTimeEnd('draw#_markupLineChanges');
|
traceTimeEnd('draw#_markupLineChanges');
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ function getColors(el) {
|
|||||||
function getMergelyContainer({ clazz = '' }) {
|
function getMergelyContainer({ clazz = '' }) {
|
||||||
const classes = [ 'mergely-editor', clazz ]
|
const classes = [ 'mergely-editor', clazz ]
|
||||||
return htmlToElement(`\
|
return htmlToElement(`\
|
||||||
<div class="${classes.join(' ')}" style="display:flex;height:100%;position:relative;"></div>`);
|
<div class="${classes.join(' ')}" style="display:flex;height:100%;position:relative;overflow:hidden;"></div>`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getMarginTemplate({ id }) {
|
function getMarginTemplate({ id }) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mergely-editor .CodeMirror-selected {
|
.mergely-editor .CodeMirror-selected {
|
||||||
background: #ffcb0f;
|
background: #0f73ff47;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mergely-splash {
|
.mergely-splash {
|
||||||
@@ -52,8 +52,6 @@
|
|||||||
.mergely-editor .merge-button {
|
.mergely-editor .merge-button {
|
||||||
height: 18px;
|
height: 18px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
width: 26px;
|
|
||||||
padding-left: 3px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* common stles */
|
/* common stles */
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ class Mergely {
|
|||||||
|
|
||||||
_setOptions(options) {
|
_setOptions(options) {
|
||||||
if (this._options && this._options._debug) {
|
if (this._options && this._options._debug) {
|
||||||
trace('api#options', opts);
|
trace('api#options');
|
||||||
}
|
}
|
||||||
const colors = dom.getColors(this.el);
|
const colors = dom.getColors(this.el);
|
||||||
this._options = {
|
this._options = {
|
||||||
@@ -186,7 +186,7 @@ class Mergely {
|
|||||||
|
|
||||||
diff() {
|
diff() {
|
||||||
if (this._options._debug) {
|
if (this._options._debug) {
|
||||||
trace('api#diff', side);
|
trace('api#diff');
|
||||||
}
|
}
|
||||||
const lhs_text = this.get('lhs');
|
const lhs_text = this.get('lhs');
|
||||||
const rhs_text = this.get('rhs');
|
const rhs_text = this.get('rhs');
|
||||||
|
|||||||
26
src/vdoc.js
26
src/vdoc.js
@@ -1,7 +1,10 @@
|
|||||||
const diff = require('./diff');
|
const diff = require('./diff');
|
||||||
|
|
||||||
|
const trace = console.log;
|
||||||
|
|
||||||
class VDoc {
|
class VDoc {
|
||||||
constructor() {
|
constructor(options) {
|
||||||
|
this.options = options;
|
||||||
this._lines = {
|
this._lines = {
|
||||||
lhs: {},
|
lhs: {},
|
||||||
rhs: {}
|
rhs: {}
|
||||||
@@ -13,6 +16,9 @@ class VDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addRender(side, change, changeId, options) {
|
addRender(side, change, changeId, options) {
|
||||||
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#addRender', side, changeId, change);
|
||||||
|
}
|
||||||
const {
|
const {
|
||||||
isCurrent,
|
isCurrent,
|
||||||
lineDiff,
|
lineDiff,
|
||||||
@@ -23,6 +29,9 @@ class VDoc {
|
|||||||
const alreadyRendered = !!this._rendered[side][changeId];
|
const alreadyRendered = !!this._rendered[side][changeId];
|
||||||
|
|
||||||
if (alreadyRendered) {
|
if (alreadyRendered) {
|
||||||
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#addRender (already rendered)', side, changeId, change);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +125,9 @@ class VDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addInlineDiff(change, changeId, { getText, ignorews, ignoreaccents, ignorecase }) {
|
addInlineDiff(change, changeId, { getText, ignorews, ignoreaccents, ignorecase }) {
|
||||||
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#addInlineDiff', changeId, change);
|
||||||
|
}
|
||||||
const { lf, lt, olf, olt } = getExtents('lhs', change);
|
const { lf, lt, olf, olt } = getExtents('lhs', change);
|
||||||
const vdoc = this;
|
const vdoc = this;
|
||||||
|
|
||||||
@@ -169,6 +181,9 @@ class VDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_setRenderedChange(side, changeId) {
|
_setRenderedChange(side, changeId) {
|
||||||
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#_setRenderedChange', side, changeId);
|
||||||
|
}
|
||||||
return this._rendered[side][changeId] = true;
|
return this._rendered[side][changeId] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,8 +197,10 @@ class VDoc {
|
|||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
update(side, changeId, editor, viewport) {
|
update(side, editor, viewport) {
|
||||||
this._setRenderedChange(side, changeId);
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#update', side, editor, viewport);
|
||||||
|
}
|
||||||
const lines = Object.keys(this._lines[side]);
|
const lines = Object.keys(this._lines[side]);
|
||||||
for (let i = 0; i < lines.length; ++i) {
|
for (let i = 0; i < lines.length; ++i) {
|
||||||
const id = lines[i];
|
const id = lines[i];
|
||||||
@@ -200,6 +217,9 @@ class VDoc {
|
|||||||
}
|
}
|
||||||
|
|
||||||
clear() {
|
clear() {
|
||||||
|
if (this.options._debug) {
|
||||||
|
trace('vdoc#clear');
|
||||||
|
}
|
||||||
for (const lineId in this._lines.lhs) {
|
for (const lineId in this._lines.lhs) {
|
||||||
this._lines.lhs[lineId].clear();
|
this._lines.lhs[lineId].clear();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user