Compare commits

..

1 Commits

Author SHA1 Message Date
Jamie Peabody
9dcbd0b910 feat(#220): Exposes Mergely's instance of CodeMirror as Mergely.CodeMirror 2025-11-15 15:33:30 +00:00
8 changed files with 22 additions and 66 deletions

View File

@@ -1,45 +1,3 @@
## [5.4.5](https://github.com/wickedest/Mergely/compare/v5.4.4...v5.4.5) (2026-02-23)
### Bug Fixes
* **#222:** Fixed issue with poor rendering performance and marker misalignment ([27778f0](https://github.com/wickedest/Mergely/commit/27778f0840895bf5e029d8c962e99890b8a0a8f6)), closes [#222](https://github.com/wickedest/Mergely/issues/222) [#227](https://github.com/wickedest/Mergely/issues/227)
## [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)

View File

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

View File

@@ -2,6 +2,9 @@ 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,6 +14,7 @@ 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.4.5",
"version": "5.3.6",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mergely",
"version": "5.4.5",
"version": "5.3.6",
"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.4.5",
"version": "5.3.6",
"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

@@ -318,7 +318,7 @@ CodeMirrorDiffView.prototype.bind = function(container) {
if (!notice) {
notice = noticeTypes.lgpl;
}
const editor = this.el;
const editor = this._queryElement(`#${this.id}`);
const splash = dom.getSplash({
notice,
left: (editor.offsetWidth - 300) / 2,
@@ -740,10 +740,6 @@ 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`]);
@@ -1094,8 +1090,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'] * rratio;
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * rratio, 5);
const mkr_rhs_y_start = change['rhs-y-start'] * lratio;
const mkr_rhs_y_end = Math.max(change['rhs-y-end'] * lratio, 5);
ctx_rhs.beginPath();
ctx_rhs.fillStyle = '#a3a3a3';
ctx_rhs.strokeStyle = '#000';
@@ -1204,7 +1200,7 @@ CodeMirrorDiffView.prototype._renderDiff = function(changes) {
CodeMirrorDiffView.prototype._queryElement = function(selector) {
const cacheName = `_element:${selector}`;
const element = this[cacheName] || this.el.querySelector(selector);
const element = this[cacheName] || document.querySelector(selector);
if (!this[cacheName]) {
this[cacheName] = element;
}

View File

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