Compare commits

...

14 Commits

Author SHA1 Message Date
Jamie Peabody
f410d0f41a fix(#222): Right-hand editor gutter marker was not aligned correctly
fix(#222): Fixed poor rendering performance in large files
2026-02-23 21:43:58 +00:00
semantic-release-bot
3651df9ad6 chore(release): 5.4.4 [skip ci]
## [5.4.4](https://github.com/wickedest/Mergely/compare/v5.4.3...v5.4.4) (2026-02-23)

### Bug Fixes

* Updated examples README.md ([f1e58f5](f1e58f58fe))
2026-02-23 19:48:25 +00:00
Jamie Peabody
f1e58f58fe fix: Updated examples README.md 2026-02-23 19:47:18 +00:00
semantic-release-bot
5cb3946182 chore(release): 5.4.3 [skip ci]
## [5.4.3](https://github.com/wickedest/Mergely/compare/v5.4.2...v5.4.3) (2026-02-23)

### Bug Fixes

* Removed whitespace from example ([69ecf76](69ecf76fe6))
2026-02-23 19:38:58 +00:00
Jamie Peabody
69ecf76fe6 fix: Removed whitespace from example 2026-02-23 19:37:43 +00:00
semantic-release-bot
93eee752a7 chore(release): 5.4.2 [skip ci]
## [5.4.2](https://github.com/wickedest/Mergely/compare/v5.4.1...v5.4.2) (2026-02-23)

### Bug Fixes

* Removed whitespace from example ([00a7917](00a79170a8))
2026-02-23 19:22:43 +00:00
Jamie Peabody
00a79170a8 fix: Removed whitespace from example 2026-02-23 18:59:11 +00:00
semantic-release-bot
c90edb3150 chore(release): 5.4.1 [skip ci]
## [5.4.1](https://github.com/wickedest/Mergely/compare/v5.4.0...v5.4.1) (2026-02-23)

### Bug Fixes

* **#225:** Fixes rendering issue when there are multiple editors ([1a2ee6a](1a2ee6af3d))
2026-02-23 18:29:31 +00:00
Fredric Johansson
1a2ee6af3d fix(#225): Fixes rendering issue when there are multiple editors 2026-02-23 16:58:35 +00:00
semantic-release-bot
aa496078fd chore(release): 5.4.0 [skip ci]
# [5.4.0](https://github.com/wickedest/Mergely/compare/v5.3.6...v5.4.0) (2025-11-15)

### Features

* **#220:** Exposes Mergely's instance of CodeMirror as Mergely.CodeMirror ([#221](https://github.com/wickedest/Mergely/issues/221)) ([d6d8d06](d6d8d06acc)), closes [#220](https://github.com/wickedest/Mergely/issues/220)
2025-11-15 15:43:30 +00:00
Jamie Peabody
d6d8d06acc feat(#220): Exposes Mergely's instance of CodeMirror as Mergely.CodeMirror (#221) 2025-11-15 15:42:29 +00:00
Moritz
b9aed167f3 Fix documentation for CM modes in README.md (#218) 2025-01-17 17:10:33 +00:00
semantic-release-bot
da71745c38 chore(release): 5.3.6 [skip ci]
## [5.3.6](https://github.com/wickedest/Mergely/compare/v5.3.5...v5.3.6) (2024-10-11)

### Bug Fixes

* **#207:** Updated documentation for search method. ([#214](https://github.com/wickedest/Mergely/issues/214)) ([350e5af](350e5af2e8)), closes [#207](https://github.com/wickedest/Mergely/issues/207)
2024-10-11 20:56:16 +00:00
Jamie Peabody
350e5af2e8 fix(#207): Updated documentation for search method. (#214)
* fix: bump dependencies

* fix: Updated documentation for search method
2024-10-11 21:52:46 +01:00
10 changed files with 84 additions and 33 deletions

View File

@@ -1,3 +1,45 @@
## [5.4.4](https://github.com/wickedest/Mergely/compare/v5.4.3...v5.4.4) (2026-02-23)
### Bug Fixes
* Updated examples README.md ([f1e58f5](https://github.com/wickedest/Mergely/commit/f1e58f58fea85628b1dd345b98b23923f05d8c2e))
## [5.4.3](https://github.com/wickedest/Mergely/compare/v5.4.2...v5.4.3) (2026-02-23)
### Bug Fixes
* Removed whitespace from example ([69ecf76](https://github.com/wickedest/Mergely/commit/69ecf76fe6066ded1efca06f9ee0ad985e8ed047))
## [5.4.2](https://github.com/wickedest/Mergely/compare/v5.4.1...v5.4.2) (2026-02-23)
### Bug Fixes
* Removed whitespace from example ([00a7917](https://github.com/wickedest/Mergely/commit/00a79170a8d4b701d6da98c1d6ea921b592fb3d1))
## [5.4.1](https://github.com/wickedest/Mergely/compare/v5.4.0...v5.4.1) (2026-02-23)
### Bug Fixes
* **#225:** Fixes rendering issue when there are multiple editors ([1a2ee6a](https://github.com/wickedest/Mergely/commit/1a2ee6af3d7d87160e72e8faca5e38cf01b36fcb))
# [5.4.0](https://github.com/wickedest/Mergely/compare/v5.3.6...v5.4.0) (2025-11-15)
### Features
* **#220:** Exposes Mergely's instance of CodeMirror as Mergely.CodeMirror ([#221](https://github.com/wickedest/Mergely/issues/221)) ([d6d8d06](https://github.com/wickedest/Mergely/commit/d6d8d06accaa4fa3a4352b95620e3e456226d444)), closes [#220](https://github.com/wickedest/Mergely/issues/220)
## [5.3.6](https://github.com/wickedest/Mergely/compare/v5.3.5...v5.3.6) (2024-10-11)
### Bug Fixes
* **#207:** Updated documentation for search method. ([#214](https://github.com/wickedest/Mergely/issues/214)) ([350e5af](https://github.com/wickedest/Mergely/commit/350e5af2e8b2e852364dc5a5729e03e3bc75358b)), closes [#207](https://github.com/wickedest/Mergely/issues/207)
## [5.3.5](https://github.com/wickedest/Mergely/compare/v5.3.4...v5.3.5) (2024-10-11)

View File

@@ -84,13 +84,15 @@ Mergely will emit an `updated` event when the editor is first initialized, and e
### Visualization modes
Mergely supports the following CodeMirror visualizations for [mode](codemirror.net/5/doc/manual.html#option_mode):
* go
* javascript
* htmlmixed
* markdown
* python
Mergely does not support any CodeMirror highlighting for different languages (xml, html, javascript etc.) out of the box.
You can compile your own Mergely-Version with support for the desired modes by adding them to diff-view.js. For example:
```
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');
```
## Options
@@ -353,7 +355,7 @@ Scrolls to the next change specified by `direction`.
doc.scrollToDiff('next');
```
### <a name="search"></a>search(side: string, needle: string)
### <a name="search"></a>search(side: string, needle: string, direction: string = 'next')
Search the editor for `needle`, scrolling to the next available match. Repeating the call will find the next available token.
@@ -363,6 +365,7 @@ Search the editor for `needle`, scrolling to the next available match. Repeating
|----|----|-----------|
|side|string|The editor side, either `lhs` or `rhs`.|
|needle|string|The text for which to search.|
|direction|string|The direction to search, either `prev` or `next`.|
#### Example

View File

@@ -1,6 +1,5 @@
# Mergely examples
## Mergely development server
To run the hot dev-server for development, you need to run:

View File

@@ -2,9 +2,6 @@ require('codemirror/addon/selection/mark-selection.js');
require('codemirror/lib/codemirror.css');
require('../src/mergely.css');
document.onreadystatechange = function () {
if (document.readyState !== 'complete') {
return;

View File

@@ -14,7 +14,6 @@ the quick brown fox
jumped over the lazy dog
`;
document.onreadystatechange = function () {
if (document.readyState !== 'complete') {
return;

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "mergely",
"version": "5.3.5",
"version": "5.4.4",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mergely",
"version": "5.3.5",
"version": "5.4.4",
"license": "(GPL-3.0 OR LGPL-3.0 OR MPL-1.1 OR SEE LICENSE IN LICENSE)",
"devDependencies": {
"@babel/core": "^7.1.6",

View File

@@ -1,6 +1,6 @@
{
"name": "mergely",
"version": "5.3.5",
"version": "5.4.4",
"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": {

View File

@@ -18,9 +18,11 @@ function CodeMirrorDiffView(el, options) {
const coords = this.cursorCoords(null, 'local');
this.scrollTo(null,
(coords.top + coords.bottom) / 2 - (this.getScrollerElement().clientHeight / 2));
});
this.init(el, options);
};
});
this.init(el, options);
};
CodeMirrorDiffView.CodeMirror = CodeMirror;
const trace = console.log;
const traceTimeStart = console.time;
@@ -316,7 +318,7 @@ CodeMirrorDiffView.prototype.bind = function(container) {
if (!notice) {
notice = noticeTypes.lgpl;
}
const editor = this._queryElement(`#${this.id}`);
const editor = this.el;
const splash = dom.getSplash({
notice,
left: (editor.offsetWidth - 300) / 2,
@@ -738,6 +740,10 @@ CodeMirrorDiffView.prototype._isChangeInView = function(side, vp, change) {
return true;
}
// there are 3 conditions to test
// 1: the change "from" is within the viewport from/to
// 2: the change "to" is within the viewport from/to
// 3: the change is so big that the viewport is within
return (change[`${side}-line-from`] >= vp.from && change[`${side}-line-from`] <= vp.to) ||
(change[`${side}-line-to`] >= vp.from && change[`${side}-line-to`] <= vp.to) ||
(vp.from >= change[`${side}-line-from`] && vp.to <= change[`${side}-line-to`]);
@@ -1088,8 +1094,8 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
ctx_lhs.strokeRect(1.5, mkr_lhs_y_start, 4.5, Math.max(mkr_lhs_y_end - mkr_lhs_y_start, 5));
ctx_lhs.stroke();
const mkr_rhs_y_start = change['rhs-y-start'] * lratio;
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * lratio, 5);
const mkr_rhs_y_start = change['rhs-y-start'] * rratio;
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * rratio, 5);
ctx_rhs.beginPath();
ctx_rhs.fillStyle = '#a3a3a3';
ctx_rhs.strokeStyle = '#000';
@@ -1198,7 +1204,7 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
CodeMirrorDiffView.prototype._queryElement = function(selector) {
const cacheName = `_element:${selector}`;
const element = this[cacheName] || document.querySelector(selector);
const element = this[cacheName] || this.el.querySelector(selector);
if (!this[cacheName]) {
this[cacheName] = element;
}

View File

@@ -253,6 +253,8 @@ class Mergely {
}
}
Mergely.CodeMirror = CodeMirrorDiffView.CodeMirror;
window.Mergely = Mergely;
module.exports = Mergely;

View File

@@ -205,9 +205,13 @@ class VDoc {
if (this.options._debug) {
trace('vdoc#update', side, editor, viewport);
}
const lines = Object.keys(this._lines[side]);
for (let i = 0; i < lines.length; ++i) {
const id = lines[i];
const keys = Object.keys(this._lines[side]);
// while Mergely diffs unicode diacritic chars (letters+mark),
// CM is by character, so diffs need to be mapped.
const mappedChars = mapLettersToChars(editor.getValue());
for (const key of keys) {
const { id } = this._lines[side][key];
if (id < viewport.from || id > viewport.to) {
continue;
}
@@ -216,7 +220,7 @@ class VDoc {
if (vline.rendered) {
continue;
}
vline.update(editor);
vline.update(editor, mappedChars);
}
}
@@ -257,7 +261,7 @@ class VLine {
this.markup.push([ charFrom, charTo, className ]);
}
update(editor) {
update(editor, mappedChars) {
if (this.rendered) {
// FIXME: probably do not need this now
console.log('already rendered', this.id);
@@ -279,18 +283,17 @@ 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());
// while Mergely diffs unicode diacritic chars (letters+mark),
// CM is by character, so diffs need to be mapped.
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 = mappedChars[charFrom];
}
if (charTo >= 0) {
toPos.ch = mapped[charTo];
toPos.ch = mappedChars[charTo];
}
this._clearMarkup.push(
editor.markText(fromPos, toPos, { className }));