1
0
mirror of synced 2025-12-16 20:04:00 +08:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Jamie Peabody
e1db3c4f9e fix: fixes undefined 'k' due to scoped 'let' 2024-03-11 19:43:28 +00:00
6 changed files with 4212 additions and 4968 deletions

View File

@@ -1,38 +1,3 @@
# [5.2.0](https://github.com/wickedest/Mergely/compare/v5.1.4...v5.2.0) (2024-06-09)
### Features
* Allows height to be not explicit height, e.g. 'inherit' or '100%' ([#196](https://github.com/wickedest/Mergely/issues/196)) ([b9e3641](https://github.com/wickedest/Mergely/commit/b9e3641c852a8926db5efdf33e65a607d5f2df5e))
## [5.1.4](https://github.com/wickedest/Mergely/compare/v5.1.3...v5.1.4) (2024-05-17)
### Bug Fixes
* removed accidental change that enabled code display modes (e.g. javascript, python, html) ([692d01f](https://github.com/wickedest/Mergely/commit/692d01f1653ae8f1163a2c6228f457549086b75d))
## [5.1.3](https://github.com/wickedest/Mergely/compare/v5.1.2...v5.1.3) (2024-05-06)
### Bug Fixes
* **chore:** updated deps ([#195](https://github.com/wickedest/Mergely/issues/195)) ([c4c6e8a](https://github.com/wickedest/Mergely/commit/c4c6e8abd8f02762d5803774789673f76a95e932))
## [5.1.2](https://github.com/wickedest/Mergely/compare/v5.1.1...v5.1.2) (2024-05-06)
### Bug Fixes
* trace only when debug enabled ([#194](https://github.com/wickedest/Mergely/issues/194)) ([60d18f8](https://github.com/wickedest/Mergely/commit/60d18f8d5c0df349b4806b2e8a6c0f79d9f8074e))
## [5.1.1](https://github.com/wickedest/Mergely/compare/v5.1.0...v5.1.1) (2024-03-11)
### Bug Fixes
* **#183:** fixes undefined 'k' due to scoped 'let' ([02e383d](https://github.com/wickedest/Mergely/commit/02e383d94d685e41cb68d945b9726bbcbfeb0ccf))
# [5.1.0](https://github.com/wickedest/Mergely/compare/v5.0.4...v5.1.0) (2023-08-27)

8943
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,6 +1,6 @@
{
"name": "mergely",
"version": "5.2.0",
"version": "5.1.0",
"description": "A javascript UI for diff/merge",
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
"author": {
@@ -57,7 +57,7 @@
"karma-sourcemap-loader": "^0.4.0",
"karma-webpack": "^5.0.0",
"mocha": "^9.1.4",
"semantic-release": "^21.1.2",
"semantic-release": "^21.0.1",
"simple-mock": "^0.8.0",
"standard-version": "^9.3.2",
"style-loader": "^3.3.1",

View File

@@ -2,6 +2,11 @@ const CodeMirror = require('codemirror');
require('codemirror/addon/search/searchcursor.js');
require('codemirror/addon/selection/mark-selection.js');
require('codemirror/lib/codemirror.css');
require('codemirror/mode/go/go.js');
require('codemirror/mode/javascript/javascript.js');
require('codemirror/mode/htmlmixed/htmlmixed.js');
require('codemirror/mode/markdown/markdown.js');
require('codemirror/mode/python/python.js');
const dom = require('./dom.js');
const VDoc = require('./vdoc');
@@ -53,7 +58,9 @@ CodeMirrorDiffView.prototype.unbind = function() {
if (this._unbound) {
return;
}
this.trace('api#unbind');
if (this.settings._debug) {
trace('api#unbind');
}
if (this._changedTimeout != null) {
clearTimeout(this._changedTimeout);
}
@@ -65,6 +72,7 @@ CodeMirrorDiffView.prototype.unbind = function() {
this.el.removeChild(this.el.lastChild);
}
if (this._origEl) {
this.el.style = this._origEl.style;
this.el.className = this._origEl.className;
}
this._unbound = true;
@@ -81,7 +89,9 @@ CodeMirrorDiffView.prototype.readOnly = function(side) {
}
CodeMirrorDiffView.prototype.lhs = function(text) {
this.trace('api#lhs', text && text.length);
if (this.settings._debug) {
trace('api#lhs', text && text.length);
}
// invalidate existing changes and current position
this.changes = [];
this._current_diff = -1;
@@ -90,25 +100,33 @@ CodeMirrorDiffView.prototype.lhs = function(text) {
CodeMirrorDiffView.prototype.rhs = function(text) {
// invalidate existing changes and current position
this.trace('api#rhs', text && text.length);
if (this.settings._debug) {
trace('api#rhs', text && text.length);
}
this.changes = [];
this._current_diff = -1;
this.editor.rhs.setValue(text);
};
CodeMirrorDiffView.prototype.update = function() {
this.trace('api#update');
if (this.settings._debug) {
trace('api#update');
}
this.el.dispatchEvent(new Event('changed'));
};
CodeMirrorDiffView.prototype.unmarkup = function() {
this.trace('api#unmarkup');
if (this.settings._debug) {
trace('api#unmarkup');
}
this._clear();
this.el.dispatchEvent(new Event('updated'));
};
CodeMirrorDiffView.prototype.scrollToDiff = function(direction) {
this.trace('api#scrollToDiff', direction);
if (this.settings._debug) {
trace('api#scrollToDiff', direction);
}
if (!this.changes.length) return;
if (direction === 'next') {
if (this._current_diff === this.changes.length - 1
@@ -125,14 +143,18 @@ CodeMirrorDiffView.prototype.scrollToDiff = function(direction) {
this._current_diff = Math.max(--this._current_diff, 0);
}
}
this.trace('change', 'current-diff', this._current_diff);
if (this.settings._debug) {
trace('change', 'current-diff', this._current_diff);
}
// _current_diff changed, refresh the view
this._scroll_to_change(this.changes[this._current_diff]);
this.setChanges(this.changes);
};
CodeMirrorDiffView.prototype.mergeCurrentChange = function(side) {
this.trace('api#mergeCurrentChange', side);
if (this.settings._debug) {
trace('api#mergeCurrentChange', side);
}
if (!this.changes.length) return;
if (side == 'lhs' && !this.lhs_cmsettings.readOnly) {
this._merge_change(this.changes[this._current_diff], 'rhs', 'lhs');
@@ -143,7 +165,9 @@ CodeMirrorDiffView.prototype.mergeCurrentChange = function(side) {
};
CodeMirrorDiffView.prototype.scrollTo = function(side, num) {
this.trace('api#scrollTo', side, num);
if (this.settings._debug) {
trace('api#scrollTo', side, num);
}
const ed = this.editor[side];
ed.setCursor(num);
ed.centerOnCursor();
@@ -157,7 +181,9 @@ CodeMirrorDiffView.prototype.setOptions = function(opts) {
...this.settings,
...opts
};
this.trace('api#setOptions', opts);
if (this.settings._debug) {
trace('api#setOptions', opts);
}
// if options set after init
if (this.editor) {
@@ -190,7 +216,9 @@ CodeMirrorDiffView.prototype.setOptions = function(opts) {
};
CodeMirrorDiffView.prototype.get = function(side) {
this.trace('api#get', side);
if (this.settings._debug) {
trace('api#get', side);
}
const ed = this.editor[side];
const value = ed.getValue();
if (value === undefined) {
@@ -200,12 +228,16 @@ CodeMirrorDiffView.prototype.get = function(side) {
};
CodeMirrorDiffView.prototype.cm = function(side) {
this.trace('api#cm', 'side');
if (this.settings._debug) {
trace('api#cm', 'side');
}
return this.editor[side];
};
CodeMirrorDiffView.prototype.search = function(side, query, direction) {
this.trace('api#search', side, query, direction);
if (this.settings._debug) {
trace('api#search', side, query, direction);
}
const editor = this.editor[side];
if (!editor.getSearchCursor) {
throw new Error('install CodeMirror search addon');
@@ -232,7 +264,9 @@ CodeMirrorDiffView.prototype.search = function(side, query, direction) {
};
CodeMirrorDiffView.prototype.resize = function() {
this.trace('api#resize');
if (this.settings._debug) {
trace('api#resize');
}
const parent = this.el;
const contentHeight = parent.offsetHeight - 2;
@@ -255,18 +289,19 @@ CodeMirrorDiffView.prototype.resize = function() {
};
CodeMirrorDiffView.prototype.bind = function(container) {
this.trace('api#bind', container);
if (this.settings._debug) {
trace('api#bind', container);
}
this._origEl = {
style: container.style,
className: container.className
};
const el = dom.getMergelyContainer({ clazz: container.className });
const computedStyle = window.getComputedStyle(container);
if (!el.style.height
&& (!computedStyle.height || computedStyle.height === '0px')
) {
if (!computedStyle.height || computedStyle.height === '0px') {
throw new Error(
`The element "${container.id}" requires an explicit height`);
}
this._origEl = {
className: container.className
};
this.id = `${container.id}`;
this.lhsId = `${container.id}-lhs`;
this.rhsId = `${container.id}-rhs`;
@@ -378,7 +413,9 @@ CodeMirrorDiffView.prototype.bind = function(container) {
}
});
this.editor.rhs.on('beforeChange', (cm, ev) => {
this.trace('event#rhs-beforeChange', ev);
if (this.settings._debug) {
trace('event#rhs-beforeChange', ev);
}
if (ev.text.length > 1
|| ((ev.from.line - ev.to.line) && ev.origin === '+delete')) {
this._clear();
@@ -386,16 +423,24 @@ CodeMirrorDiffView.prototype.bind = function(container) {
});
this.editor.lhs.on('change', (instance, ev) => {
this.trace('event#lhs-change');
if (this.settings._debug) {
trace('event#lhs-change');
}
this._changing();
this.trace('event#lhs-change [emitted]');
if (this.settings._debug) {
trace('event#lhs-change [emitted]');
}
});
this.editor.lhs.on('scroll', () => {
if (this._skipscroll.lhs) {
this.trace('event#lhs-scroll (skipped)');
if (this.settings._debug) {
trace('event#lhs-scroll (skipped)');
}
return;
} else {
this.trace('event#lhs-scroll');
if (this.settings._debug) {
trace('event#lhs-scroll');
}
}
// firefox scroll-linked effect render issue
setTimeout(() => {
@@ -403,15 +448,21 @@ CodeMirrorDiffView.prototype.bind = function(container) {
}, 1);
});
this.editor.rhs.on('change', (instance, ev) => {
this.trace('event#rhs-change', ev);
if (this.settings._debug) {
trace('event#rhs-change', ev);
}
this._changing();
});
this.editor.rhs.on('scroll', () => {
if (this._skipscroll.rhs) {
this.trace('event#rhs-scroll (skipped)');
if (this.settings._debug) {
trace('event#rhs-scroll (skipped)');
}
return;
} else {
this.trace('event#rhs-scroll');
if (this.settings._debug) {
trace('event#rhs-scroll');
}
}
// firefox scroll-linked effect render issue
setTimeout(() => {
@@ -424,7 +475,7 @@ CodeMirrorDiffView.prototype.bind = function(container) {
const resize = () => {
if (this.settings._debug) {
traceTimeStart('event#resize');
this.trace('event#resize [start]');
trace('event#resize [start]');
}
this.resize();
if (this.settings._debug) {
@@ -481,12 +532,16 @@ CodeMirrorDiffView.prototype.bind = function(container) {
}
this.editor.lhs.on('gutterClick', (cm, n, gutterClass, ev) => {
this.trace('event#gutterClick', 'lhs', n, ev);
if (this.settings._debug) {
trace('event#gutterClick', 'lhs', n, ev);
}
gutterClicked.call(this, 'lhs', n, ev);
});
this.editor.rhs.on('gutterClick', (cm, n, gutterClass, ev) => {
this.trace('event#gutterClick', 'rhs', n, ev);
if (this.settings._debug) {
trace('event#gutterClick', 'rhs', n, ev);
}
gutterClicked.call(this, 'rhs', n, ev);
});
@@ -634,14 +689,18 @@ CodeMirrorDiffView.prototype._scrolling = function({ side }) {
const vp = this.editor[oside].getViewport();
let scroll = true;
if (last_change) {
this.trace('scroll#_scrolling', 'last change before midline', last_change);
if (this.settings._debug) {
trace('scroll#_scrolling', 'last change before midline', last_change);
}
if (midline.line >= vp.from && midline <= vp.to) {
scroll = false;
}
}
if (scroll || force_scroll) {
// scroll the other side
this.trace('scroll#_scrolling', 'other side', oside, 'pos:', top_to - top_adjust);
if (this.settings._debug) {
trace('scroll#_scrolling', 'other side', oside, 'pos:', top_to - top_adjust);
}
// disable linked scroll events for the opposite editor because this
// triggers the next one explicitly, and we don't want to link the
@@ -649,21 +708,21 @@ CodeMirrorDiffView.prototype._scrolling = function({ side }) {
// coming in 2s, so this will "link" scrolling the other editor to
// this editor until this editor stops scrolling and times out.
this._skipscroll[oside] = true;
this.trace('scroll#set oside skip set:', oside, this._skipscroll);
trace('scroll#set oside skip set:', oside, this._skipscroll);
if (this._linkedScrollTimeout[oside]) {
clearTimeout(this._linkedScrollTimeout[oside]);
this.trace('scroll#clearing timeout:', this._skipscroll);
trace('scroll#clearing timeout:', this._skipscroll);
}
this._linkedScrollTimeout[oside] = setTimeout(() => {
this._skipscroll[oside] = false;
this.trace('scroll#set oside skip unset:', oside, this._skipscroll);
trace('scroll#set oside skip unset:', oside, this._skipscroll);
}, 100);
const top = top_to - top_adjust;
// scroll the opposite editor
this.editor[oside].scrollTo(left_to, top);
} else {
this.trace('scroll#_scrolling', 'not scrolling other side');
} else if (this.settings._debug) {
trace('scroll#_scrolling', 'not scrolling other side');
}
this._renderChanges();
@@ -674,19 +733,23 @@ CodeMirrorDiffView.prototype._scrolling = function({ side }) {
CodeMirrorDiffView.prototype._changing = function() {
if (!this.settings.autoupdate) {
this.trace('change#_changing autoupdate is disabled');
if (this.settings._debug) {
trace('change#_changing autoupdate is disabled');
}
return;
}
if (this.settings._debug) {
traceTimeStart('change#_changing');
this.trace('change#_changing [start]');
trace('change#_changing [start]');
}
const handleChange = () => {
this._changedTimeout = null;
this.el.dispatchEvent(new Event('changed'));
};
if (this.settings.change_timeout > 0) {
this.trace('change#setting timeout', this.settings.change_timeout)
if (this.settings._debug) {
trace('change#setting timeout', this.settings.change_timeout)
}
if (this._changedTimeout != null) {
clearTimeout(this._changedTimeout);
}
@@ -700,7 +763,9 @@ CodeMirrorDiffView.prototype._changing = function() {
};
CodeMirrorDiffView.prototype.setChanges = function(changes) {
this.trace('change#setChanges');
if (this.settings._debug) {
trace('change#setChanges');
}
this._clear();
// after clear, set the new changes
this.changes = changes;
@@ -710,7 +775,7 @@ CodeMirrorDiffView.prototype.setChanges = function(changes) {
CodeMirrorDiffView.prototype._renderChanges = function() {
if (this.settings._debug) {
traceTimeStart('draw#_renderChanges');
this.trace('draw#_renderChanges [start]', this.changes.length, 'changes');
trace('draw#_renderChanges [start]', this.changes.length, 'changes');
}
this._clearCanvases();
this._calculateOffsets(this.changes);
@@ -753,9 +818,6 @@ CodeMirrorDiffView.prototype._set_top_offset = function (side) {
// this is the distance from the top of the screen to the top of the
// content of the first codemirror editor
const topnode = this._queryElement('.CodeMirror-measure');
if (!topnode.offsetParent) {
return false;
}
const top_offset = topnode.offsetParent.offsetTop + 4;
// restore editor's scroll position
@@ -1041,9 +1103,12 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
const ctx_lhs = mcanvas_lhs.getContext('2d');
const ctx_rhs = mcanvas_rhs.getContext('2d');
this.trace('draw#_renderDiff', 'visible page height', ex.visible_page_height);
this.trace('draw#_renderDiff', 'scroller-top lhs', ex.lhs_scroller.scrollTop);
this.trace('draw#_renderDiff', 'scroller-top rhs', ex.rhs_scroller.scrollTop);
if (this.settings._debug
&& this.settings._debug) {
trace('draw#_renderDiff', 'visible page height', ex.visible_page_height);
trace('draw#_renderDiff', 'scroller-top lhs', ex.lhs_scroller.scrollTop);
trace('draw#_renderDiff', 'scroller-top rhs', ex.rhs_scroller.scrollTop);
}
ex.lhs_margin.removeEventListener('click', this._handleLhsMarginClick);
ex.rhs_margin.removeEventListener('click', this._handleRhsMarginClick);
@@ -1068,16 +1133,17 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
const rhs_y_end = change['rhs-y-end'] - rhsScrollTop;
if (Number.isNaN(lhs_y_start)) {
this.trace(
'draw#_renderDiff unexpected NaN',
change['lhs-y-start'], change['lhs-y-end']
);
trace('draw#_renderDiff', 'unexpected NaN',
change['lhs-y-start'], change['lhs-y-end']);
continue;
}
// draw margin indicators
this.trace('draw#_renderDiff', 'draw1', 'marker',
if (this.settings._debug
&& this.settings._debug) {
trace('draw#_renderDiff', 'draw1', 'marker',
lhs_y_start, lhs_y_end, rhs_y_start, rhs_y_end);
}
const mkr_lhs_y_start = change['lhs-y-start'] * lratio;
const mkr_lhs_y_end = Math.max(change['lhs-y-end'] * lratio, 5);
@@ -1206,10 +1272,4 @@ CodeMirrorDiffView.prototype._queryElement = function(selector) {
return this[cacheName];
}
CodeMirrorDiffView.prototype.trace = function(...args) {
if (this.settings._debug) {
console.log(...args);
}
}
module.exports = CodeMirrorDiffView;

View File

@@ -46,9 +46,7 @@ class Mergely {
}
const computedStyle = window.getComputedStyle(element);
if (!element.style.height
&& (!computedStyle.height || computedStyle.height === '0px')
) {
if (!computedStyle.height || computedStyle.height === '0px') {
throw new Error(
`The element "${selector}" requires an explicit height`);
}

View File

@@ -15,10 +15,6 @@ module.exports = (mode) => {
...webpackDevConfig.output,
path: path.join(__dirname, 'lib'),
filename: './[name].js',
library: {
name: 'mergely',
type: 'umd',
}
},
optimization: {
minimize: true,