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

Compare commits

..

11 Commits

Author SHA1 Message Date
Jamie Peabody
ce407dac3f fix: fixes firefox scroll-linked effect issue 2023-04-23 11:30:19 +01:00
Jamie Peabody
a01cadbf64 fix: fixes firefox scroll-linked effect issue 2023-04-23 10:29:16 +01:00
Jamie Peabody
fbe670c92a chore(ci): ignore alpha, beta, next on branch 2023-04-23 10:28:48 +01:00
Jamie Peabody
88f21e2bc7 chore(ci): package-lock.json 2023-04-22 16:01:38 +01:00
Jamie Peabody
4160ab4f6e chore(ci): test 2023-04-22 15:59:44 +01:00
Jamie Peabody
16f1d2016d chore(ci): alpha, beta, next branches 2023-04-22 15:57:48 +01:00
Jamie Peabody
347a3f56ff chore(ci): updated webpack 2023-04-22 14:41:21 +01:00
Jamie Peabody
88d4a62a04 chore: updated examples 2023-04-22 14:40:58 +01:00
Jamie Peabody
b3e7b48d11 feat: dark mode 2023-04-22 14:13:30 +01:00
Jamie Peabody
fcea4efe2f chore: tweaked no-start/end styles 2023-04-22 13:44:33 +01:00
Jamie Peabody
080b8fd7b5 feat: v5
BREAKING CHANGE: Mergely is no longer a jQuery plugin.

BREAKING CHANGE: Removed `options.autoresize`

BREAKING CHANGE: Removed `options.editor_width`

BREAKING CHANGE: Removed `options.editor_height`

BREAKING CHANGE: Removed `options.fadein`

BREAKING CHANGE: Removed `options.fgcolor`

BREAKING CHANGE: Removed `options.resize`

BREAKING CHANGE: Removed `options.width`

BREAKING CHANGE: Removed `options.height`

BREAKING CHANGE: Removed `options.loaded` callback

BREAKING CHANGE: Removed `options.resized` callback

BREAKING CHANGE: Removed styles `.mergely-resizer`, `.mergely-full-screen-0`, and `.mergely-full-screen-8`

BREAKING CHANGE: Changed default for `options.change_timeout` changed from `150` to `50`.

BREAKING CHANGE: No longer automatically scrolls to first change.

feat: CodeMirror is now an explicit dependency.

feat: No longer necessary to separately require codemirror/addon/search/searchcursor

feat: No longer necessary to separately require codemirror/addon/selection/mark-selection

feat: `mergely.js` is now unminimized, and added new minimized version `mergely.min.js`

feat: Gutter click now scrolls to any line

feat: Mergely now emits `resize` event on resize

feat: The UI is now non-blocking as diff now runs in background

feat: Added support to provide `options.lhs` and `options.rhs` as strings

feat: #16 added titles to editor.mergely.com

fix: #165 block of changes at end of file are now distinguishable

fix: #140 fixed performance issue with large files

fix: Fixed issue where canvas markup was not rendered when `viewport` enabled

fix: Fixed timing issue where swap sides may not work as expected.

fix: Fixed issue where unmarkup did not emit an updated event.

fix: Fixed documentation issue where `merge` incorrectly stated: from the specified `side` to the opposite side.

fix: Fixed performance issue scrolling

fix: Fixed issue where initial render scrolled to first change, showing it at the bottom (as opposed to middle as expected)

fix: Fixed issue where line-diffs failed to diff non-alphanumeric characters
2023-04-22 12:41:12 +01:00
17 changed files with 4191 additions and 5345 deletions

View File

@@ -1,11 +0,0 @@
branches:
- master
- name: alpha
prerelease: true
plugins:
- "@semantic-release/commit-analyzer"
- "@semantic-release/release-notes-generator"
- "@semantic-release/changelog"
- "@semantic-release/npm"
- "@semantic-release/git"
- "@semantic-release/github"

View File

@@ -1,111 +1,7 @@
## [5.3.1](https://github.com/wickedest/Mergely/compare/v5.3.0...v5.3.1) (2024-06-19)
### Bug Fixes
* Fixed a regression rendering inline markup for numbers, punctuation, and symbols ([#199](https://github.com/wickedest/Mergely/issues/199)) ([c40672c](https://github.com/wickedest/Mergely/commit/c40672c458723bdd0d9a0062ef1457e435866765))
# [5.3.0](https://github.com/wickedest/Mergely/compare/v5.2.0...v5.3.0) (2024-06-16)
### Features
* Supports unicode diacritical marks when rendering line diff (fixes [#169](https://github.com/wickedest/Mergely/issues/169)) ([#197](https://github.com/wickedest/Mergely/issues/197)) ([a469a65](https://github.com/wickedest/Mergely/commit/a469a6510122356a7cae3fb1259e999e6cc34c94))
# [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)
### Features
* support CM modes: go, javascript, htmlmixed, markdown, python ([827487a](https://github.com/wickedest/Mergely/commit/827487a5983cb89ef41415435d44239e35983b9a))
## [5.0.4](https://github.com/wickedest/Mergely/compare/v5.0.3...v5.0.4) (2023-08-27)
### Bug Fixes
* updated CDN example ([dec1e95](https://github.com/wickedest/Mergely/commit/dec1e9509d94811914e77cbc33dc1aaedf154f7c))
## [5.0.3](https://github.com/wickedest/Mergely/compare/v5.0.2...v5.0.3) (2023-08-27)
### Bug Fixes
* Updated docs with CDN example ([254adf1](https://github.com/wickedest/Mergely/commit/254adf15ab09fe9c5c3dff542d0a7f62ce2c9782))
## [5.0.2](https://github.com/wickedest/Mergely/compare/v5.0.1...v5.0.2) (2023-04-24)
### Bug Fixes
* **scroll:** fixed issue where first rhs scroll was unlinked ([7b2040c](https://github.com/wickedest/Mergely/commit/7b2040c6ad17ea70a09720f54d9a255cdc57cd67))
## [5.0.1](https://github.com/wickedest/Mergely/compare/v5.0.0...v5.0.1) (2023-04-23)
### Bug Fixes
* update release ([a8b497b](https://github.com/wickedest/Mergely/commit/a8b497bc9b68beb5d8265106d9f010aa9489dd17))
# Changelog
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
### [5.0.0](https://github.com/wickedest/Mergely/compare/v4.3.9...v5.0.0) (2023-04-23)
### BREAKING CHANGES
- Mergely is no longer a jQuery plugin.
- Removed options.autoresize
- Removed options.editor_width
- Removed options.editor_height
- Removed options.fadein
- Removed options.fgcolor
- Removed options.resize
- Removed options.width
- Removed options.height
- Removed options.loaded callback
- Removed options.resized callback
- Removed styles .mergely-resizer, .mergely-full-screen-0, and .mergely-full-screen-8
- Changed default for options.change_timeout changed from 150 to 50.
- No longer automatically scrolls to first change.
### 4.3.9 (2022-01-19)

View File

@@ -4,7 +4,7 @@
https://mergely.com
Mergely is a JavaScript component for differencing and merging files interactively in a browser (diff/merge). It provides a rich API that enables you to easily integrate Mergely into your existing web application. It is suitable for comparing text files online, such as .txt, .html, .xml, .c, .cpp, .java, .js, etc.
Mergely is a JavaScript component for differencing and merging files interactively in a browser (diff/merge). It provides a rich API that enables you to easily integrate Mergely into your existing web application. It is suitable for comparing text files online, for example, .txt, .html, .xml, .c, .cpp, .java, etc.
Mergely has a JavaScript implementation of the Longest Common Subsequence (LCS) diff algorithm, and a customizable markup engine. It computes the diff within the browser.
@@ -36,11 +36,11 @@ rm -rf .git
### Usage via CDN
Add the following to the `<head>` of your target HTML source file. Note that `codemirror` is bundled.
Unpack mergely.tgz into a folder, for example, `./lib`, and add the following to the `<head>` of your target HTML source file.
```html
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.css"></script>
```
### Synchronous initialization
@@ -82,16 +82,6 @@ Mergely will emit an `updated` event when the editor is first initialized, and e
</body>
```
### Visualization modes
Mergely supports the following CodeMirror visualizations for [mode](codemirror.net/5/doc/manual.html#option_mode):
* go
* javascript
* htmlmixed
* markdown
* python
## Options
|Option|Type|Default value|Description|

View File

@@ -1,38 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Mergely - Example full page editor</title>
<meta http-equiv="X-UA-Compatible" content="chrome=1, IE=edge">
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<meta name="description" content="" />
<meta name="keywords" content="mergely,diff,merge,compare" />
<meta name="author" content="Jamie Peabody" />
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<!-- Mergely -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.min.js"></script>
<link type="text/css" rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mergely/5.0.0/mergely.css" />
<style type="text/css">
html, body {
height: 100%;
margin: 0;
}
#compare {
height: inherit;
}
</style>
</head>
<body>
<div id="compare"></div>
<script>
const mergely = new Mergely('#compare');
mergely.once('updated', () => {
mergely.lhs('the quick red fox\njumped over the hairy dog');
mergely.rhs('the quick brown fox\njumped over the lazy dog');
});
</script>
</body>
</html>

View File

@@ -21,9 +21,6 @@ This example demonstrates the minimum amount of code required to use Mergely.
<h1>Examples</h1>
<dl>
<dt><a href="cdn.html">cdn.html</a></dt>
<dd>Demonstrates how to use Mergely with CDN.</dd>
<dt><a href="editor.html">editor.html</a></dt>
<dd>An example editor showcasing some of Mergely's API features.</dd>

View File

@@ -22,7 +22,6 @@
"changelog" : {
"commitTypes": [
"docs",
"feat",
"fix",
"perf",

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.3.1",
"version": "5.0.0-rc0",
"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": {
@@ -14,7 +14,7 @@
},
"repository": {
"type": "git",
"url": "git@github.com:wickedest/Mergely.git"
"url": "git+https://github.com/wickedest/Mergely.git"
},
"main": "lib/mergely.js",
"files": [
@@ -36,8 +36,6 @@
"@commitlint/cli": "^17.6.1",
"@commitlint/config-conventional": "^15.0.0",
"@commitlint/prompt-cli": "^15.0.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/git": "^10.0.1",
"babel-loader": "^8.2.3",
"babel-plugin-syntax-dynamic-import": "^6.18.0",
"chai": "^4.3.4",
@@ -57,7 +55,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,7 +2,6 @@ const CodeMirror = require('codemirror');
require('codemirror/addon/search/searchcursor.js');
require('codemirror/addon/selection/mark-selection.js');
require('codemirror/lib/codemirror.css');
const dom = require('./dom.js');
const VDoc = require('./vdoc');
@@ -45,15 +44,16 @@ CodeMirrorDiffView.prototype.init = function(el, options = {}) {
lineNumbers: this.settings.line_numbers,
gutters: (this.settings.line_numbers && [ 'merge', 'CodeMirror-linenumbers' ]) || [],
};
this._vdoc = new VDoc({ _debug: this.settings._debug });
this._linkedScrollTimeout = {};
this._vdoc = new VDoc();
};
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 +65,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 +82,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 +93,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 +136,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 +158,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 +174,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 +209,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 +221,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 +257,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 +282,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 +406,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 +416,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 +441,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 +468,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 +525,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);
});
@@ -513,7 +561,7 @@ CodeMirrorDiffView.prototype._clearMarkup = function () {
traceTimeStart('draw#_clearMarkup');
}
this._vdoc.clear();
this._vdoc = new VDoc({ _debug: this.settings._debug });
this._vdoc = new VDoc();
if (this.settings._debug) {
traceTimeEnd('draw#_clearMarkup');
}
@@ -634,14 +682,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 +701,18 @@ 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);
if (this._linkedScrollTimeout[oside]) {
clearTimeout(this._linkedScrollTimeout[oside]);
this.trace('scroll#clearing timeout:', this._skipscroll);
if (this._linkedScrollTimeout) {
clearTimeout(this._linkedScrollTimeout);
}
this._linkedScrollTimeout[oside] = setTimeout(() => {
this._linkedScrollTimeout = setTimeout(() => {
this._skipscroll[oside] = false;
this.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 +723,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 +753,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 +765,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 +808,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
@@ -943,10 +995,14 @@ CodeMirrorDiffView.prototype._markupLineChanges = function (changes) {
}
}
led.operation(() => {
vdoc.update('lhs', led, lhsvp);
for (let i = 0; i < changes.length; ++i) {
vdoc.update('lhs', i, led, lhsvp);
}
});
red.operation(() => {
vdoc.update('rhs', red, rhsvp);
for (let i = 0; i < changes.length; ++i) {
vdoc.update('rhs', i, red, rhsvp);
}
});
if (this.settings._debug) {
traceTimeEnd('draw#_markupLineChanges');
@@ -1041,9 +1097,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 +1127,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',
lhs_y_start, lhs_y_end, rhs_y_start, rhs_y_end);
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 +1266,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

@@ -146,7 +146,7 @@ diff.prototype._sms = function(lhs_ctx, lhs_lower, lhs_upper, rhs_ctx, rhs_lower
}
}
// Extend the reverse path.
for (let k = kup - d; k <= kup + d; k += 2) {
for (k = kup - d; k <= kup + d; k += 2) {
// find the only or better starting point
if (k === kup + d) {
x = vector_u[offset_up + k - 1]; // up
@@ -241,14 +241,10 @@ function CodeifyText(lhs, rhs, options) {
this.ctxs = {};
this.options = options;
this.options.split = this.options.split || 'lines';
const exp = /\p{Letter}\p{Mark}*|\p{Number}\p{Mark}*|\p{Punctuation}\p{Mark}*|\p{Symbol}\p{Mark}*|\p{White_Space}/gu;
if (typeof lhs === 'string') {
if (this.options.split === 'chars') {
console.log('HERE')
// split characters and include their diacritical marks
this.lhs = lhs.match(exp) || [];
// this.lhs = [...lhs];
this.lhs = lhs.split('');
} else if (this.options.split === 'words') {
this.lhs = lhs.split(/\s/);
} else if (this.options.split === 'lines') {
@@ -259,9 +255,7 @@ function CodeifyText(lhs, rhs, options) {
}
if (typeof rhs === 'string') {
if (this.options.split === 'chars') {
// split characters and include their diacritical marks
this.rhs = rhs.match(exp) || [];
// this.rhs = [...rhs];
this.rhs = rhs.split('');
} else if (this.options.split === 'words') {
this.rhs = rhs.split(/\s/);
} else if (this.options.split === 'lines') {

View File

@@ -17,7 +17,7 @@
}
.mergely-editor .CodeMirror-selected {
background: #0f73ff47;
background: #ffcb0f;
}
.mergely-splash {
@@ -52,6 +52,8 @@
.mergely-editor .merge-button {
height: 18px;
cursor: pointer;
width: 26px;
padding-left: 3px;
}
/* common stles */

View File

@@ -23,8 +23,7 @@ const defaultOptions = {
vpcolor: 'rgba(0, 0, 200, 0.5)',
license: 'lgpl',
cmsettings: {
styleSelectedText: true,
mode: null
styleSelectedText: true
},
lhs_cmsettings: {},
rhs_cmsettings: {},
@@ -46,9 +45,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`);
}
@@ -117,7 +114,7 @@ class Mergely {
_setOptions(options) {
if (this._options && this._options._debug) {
trace('api#options');
trace('api#options', opts);
}
const colors = dom.getColors(this.el);
this._options = {

View File

@@ -1,14 +1,7 @@
const diff = require('./diff');
const trace = console.log;
const expLetters = new RegExp(
/\p{Letter}\p{Mark}*|\p{Number}\p{Mark}*|\p{Punctuation}\p{Mark}*|\p{Symbol}\p{Mark}*|\p{White_Space}/gu
);
class VDoc {
constructor(options) {
this.options = options;
constructor() {
this._lines = {
lhs: {},
rhs: {}
@@ -20,9 +13,6 @@ class VDoc {
}
addRender(side, change, changeId, options) {
if (this.options._debug) {
trace('vdoc#addRender', side, changeId, change);
}
const {
isCurrent,
lineDiff,
@@ -33,9 +23,6 @@ class VDoc {
const alreadyRendered = !!this._rendered[side][changeId];
if (alreadyRendered) {
if (this.options._debug) {
trace('vdoc#addRender (already rendered)', side, changeId, change);
}
return;
}
@@ -129,9 +116,6 @@ class VDoc {
}
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 vdoc = this;
@@ -185,9 +169,6 @@ class VDoc {
}
_setRenderedChange(side, changeId) {
if (this.options._debug) {
trace('vdoc#_setRenderedChange', side, changeId);
}
return this._rendered[side][changeId] = true;
}
@@ -201,10 +182,8 @@ class VDoc {
return line;
}
update(side, editor, viewport) {
if (this.options._debug) {
trace('vdoc#update', side, editor, viewport);
}
update(side, changeId, editor, viewport) {
this._setRenderedChange(side, changeId);
const lines = Object.keys(this._lines[side]);
for (let i = 0; i < lines.length; ++i) {
const id = lines[i];
@@ -221,9 +200,6 @@ class VDoc {
}
clear() {
if (this.options._debug) {
trace('vdoc#clear');
}
for (const lineId in this._lines.lhs) {
this._lines.lhs[lineId].clear();
}
@@ -279,18 +255,15 @@ class VLine {
editor.setGutterMarker(this.id, name, item);
}
if (this.markup.length) {
// while Mergely diffs unicode chars (letters+mark), CM is by character,
// so diffs need to be mapped.
const mapped = mapLettersToChars(editor.getValue());
for (const markup of this.markup) {
const [ charFrom, charTo, className ] = markup;
const fromPos = { line: this.id };
const toPos = { line: this.id };
if (charFrom >= 0) {
fromPos.ch = mapped[charFrom];
fromPos.ch = charFrom;
}
if (charTo >= 0) {
toPos.ch = mapped[charTo];
toPos.ch = charTo;
}
this._clearMarkup.push(
editor.markText(fromPos, toPos, { className }));
@@ -341,15 +314,4 @@ function getExtents(side, change) {
};
}
function mapLettersToChars(text) {
let match;
let mapped = {};
let index = 0;
expLetters.lastIndex = 0;
while ((match = expLetters.exec(text)) !== null) {
mapped[index++] = match.index;
}
return mapped;
}
module.exports = VDoc;

View File

@@ -42,7 +42,6 @@ describe('markup', () => {
const LHS_CHANGE_START = '.mergely.lhs.c.CodeMirror-linebackground.start';
const LHS_CHANGE_END = '.mergely.lhs.c.CodeMirror-linebackground.end';
const LHS_CHANGE_START_AND_END = '.mergely.lhs.c.CodeMirror-linebackground.start.end';
const RHS_CHANGE_START = '.mergely.rhs.c.CodeMirror-linebackground.start';
const RHS_CHANGE_END = '.mergely.rhs.c.CodeMirror-linebackground.end';
@@ -234,133 +233,7 @@ describe('markup', () => {
expect(rhs_spans[1].innerText).to.equal('h');
expect(rhs_spans[2].innerText).to.equal('ir');
}
},
{
name: 'single word single diacritic non-spacing marks',
lhs: 'كلمة',
rhs: 'كَلمة',
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_CHANGE_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_END + '.cid-0')).to.have.length(1);
const lhs_spans = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
expect(lhs_spans).to.have.length(1);
expect(lhs_spans[0].innerText).to.equal('ك');
const rhs_spans = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
expect(rhs_spans).to.have.length(1);
expect(rhs_spans[0].innerText).to.equal('كَ');
}
},
{
name: 'single word multiple diacritic non-spacing marks',
lhs: ['\u006E', '\u0061', '\u0314', '\u0065'].join(''), // na̔e
rhs: ['\u006E', '\u0061', '\u0314', '\u034A', '\u0065'].join(''), // na̔͊e
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_CHANGE_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_END + '.cid-0')).to.have.length(1);
const lhs_spans = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
expect(lhs_spans).to.have.length(1);
expect(lhs_spans[0].innerText).to.equal(['\u0061', '\u0314'].join(''));
const rhs_spans = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
expect(rhs_spans).to.have.length(1);
expect(rhs_spans[0].innerText).to.equal('a̔͊');
}
},
{
name: 'multiple words diacritic non-spacing marks',
lhs: 'كلمة اخرى',
rhs: 'كْلمة اخرى',
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_CHANGE_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_END + '.cid-0')).to.have.length(1);
const lhs_spans = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
expect(lhs_spans).to.have.length(1);
expect(lhs_spans[0].innerText).to.equal('ك');
const rhs_spans = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
expect(rhs_spans).to.have.length(1);
expect(rhs_spans[0].innerText).to.equal('كْ');
}
},
{
name: 'nonnormalizable diacritic non-spacing marks',
lhs: 'naeg',
// there are 2 marks on 'e', tilde (0303) and x (0353)
rhs: ['\u006E', '\u0061', '\u0353', '\u0065', '\u0353', '\u0303', '\u0067'].join(''),
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_CHANGE_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_END + '.cid-0')).to.have.length(1);
const lhs_spans = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
expect(lhs_spans).to.have.length(1);
expect(lhs_spans[0].innerText).to.equal('ae');
const rhs_spans = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
expect(rhs_spans).to.have.length(1);
expect(rhs_spans[0].innerText).to.equal(
['\u0061', '\u0353', '\u0065', '\u0353', '\u0303'].join('')
);
}
},
{
name: 'nonnormalizable diacritic non-spacing marks',
lhs: [
'\u0065', '\u0353', '\u0303',
'\u0065', '\u0353', '\u0303',
'\u0065', '\u0353', '\u0303',
'x',
'\u0065', '\u0353', '\u0303',
].join(''),
// there are 2 marks on 'e', tilde (0303) and x (0353)
rhs: [
'\u0065', '\u0353', '\u0303',
'\u0065', '\u0353', '\u0303',
'\u0065', '\u0353', '\u0303',
'y',
'\u0065', '\u0353', '\u0303',
].join(''),
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_CHANGE_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_START + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(RHS_CHANGE_END + '.cid-0')).to.have.length(1);
const lhs_spans = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
expect(lhs_spans).to.have.length(1);
expect(lhs_spans[0].innerText).to.equal('x');
const rhs_spans = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
expect(rhs_spans).to.have.length(1);
expect(rhs_spans[0].innerText).to.equal('y');
}
},
{
name: 'Changes with non-letter chars',
lhs: '~# 00 == ! (dog) \n',
rhs: '~? 11 ++ ] (fox) .\n',
only: true,
check: (editor) => {
expect(editor.querySelectorAll(LHS_CHANGE_START_AND_END + '.cid-0')).to.have.length(1);
expect(editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0')).to.have.length(6);
expect(editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0')).to.have.length(7);
const lhs_changes = editor.querySelectorAll(LHS_INLINE_TEXT + '.cid-0');
const rhs_changes = editor.querySelectorAll(RHS_INLINE_TEXT + '.cid-0');
const lhs_values = [];
for (const value of lhs_changes.values()) {
lhs_values.push(value.innerText);
}
const rhs_values = [];
for (const value of rhs_changes.values()) {
rhs_values.push(value.innerText);
}
console.log(lhs_values);
console.log(rhs_values);
expect(lhs_values).to.deep.equal(['#', '00', '==', '!', 'd', 'g']);
expect(rhs_values).to.deep.equal(['?', '11', '++', ']', 'f', 'x', '.']);
}
},
}
];
// to debug, add `only: true` to the test `opts` above, and run `npm run debug`

View File

@@ -22,8 +22,7 @@ const defaultOptions = {
vpcolor: 'rgba(0, 0, 200, 0.5)',
license: 'lgpl',
cmsettings: {
styleSelectedText: true,
mode: null
styleSelectedText: true
},
_debug: false
};

View File

@@ -1,5 +1,4 @@
const path = require('path')
const chalk = require('chalk');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
@@ -51,8 +50,8 @@ module.exports = {
compiler.hooks.entryOption.tap('MyPlugin', (context, entry) => {
console.log('-'.repeat(78));
console.log('Applications:');
console.log(chalk.bold(chalk.underline(chalk.cyan('http://localhost:8080/app.html'))));
console.log(chalk.bold(chalk.underline(chalk.cyan('http://localhost:8080/app-styles.html'))));
console.log('http://localhost:8080/app.html');
console.log('http://localhost:8080/app-styles.html');
console.log('-'.repeat(78));
});
}

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,