From 1c80cd644b2750c9c6da0e9dc4cca4b75675022a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dariusz=20Jarz=C4=99bski?= Date: Thu, 18 Dec 2025 12:40:25 +0100 Subject: [PATCH] Add integration with CKEditor track changes feature. --- packages/ckeditor5/src/integration.js | 11 ++++++++--- packages/ckeditor5/src/plugin.js | 25 ++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/packages/ckeditor5/src/integration.js b/packages/ckeditor5/src/integration.js index 2fc6bc886..64ba14069 100644 --- a/packages/ckeditor5/src/integration.js +++ b/packages/ckeditor5/src/integration.js @@ -170,7 +170,10 @@ export default class CKEditor5Integration extends IntegrationModel { // Remove selection if (!viewSelection.isCollapsed) { for (const range of viewSelection.getRanges()) { - writer.remove(this.editorObject.editing.mapper.toModelRange(range)); + const modelRange = this.editorObject.editing.mapper.toModelRange(range); + const modelSelection = this.editorObject.model.createSelection(modelRange); + + this.editorObject.model.deleteContent(modelSelection); } } @@ -189,7 +192,7 @@ export default class CKEditor5Integration extends IntegrationModel { if (mathml) { this.editorObject.model.insertObject(modelElementNew, position); } - writer.remove(modelElementOld); + this.editorObject.model.deleteContent(this.editorObject.model.createSelection(modelElementOld,'on')); } // eslint-disable-next-line consistent-return @@ -280,7 +283,9 @@ export default class CKEditor5Integration extends IntegrationModel { } } - writer.remove(range); + const modelSelection = this.editorObject.model.createSelection(range); + + this.editorObject.model.deleteContent(modelSelection); writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition); }); } else { diff --git a/packages/ckeditor5/src/plugin.js b/packages/ckeditor5/src/plugin.js index a31156ae5..81c6f743f 100644 --- a/packages/ckeditor5/src/plugin.js +++ b/packages/ckeditor5/src/plugin.js @@ -43,7 +43,10 @@ export default class MathType extends Plugin { currentInstance = integration; // Add the MathType and ChemType commands to the editor - this._addCommands(); + this._addCommands(integration); + + // Add the track changes feature integration + this._addTrackChangesIntegration(integration); // Add the buttons for MathType and ChemType this._addViews(integration); @@ -579,4 +582,24 @@ export default class MathType extends Plugin { Latex, }; } + + _addTrackChangesIntegration(integration) { + const { editor } = this; + + if (editor.plugins.has("TrackChangesEditing")) { + const trackChangesEditing = editor.plugins.get("TrackChangesEditing"); + + // Makes MathType and ChemType buttons available when editor is in the track changes mode + trackChangesEditing.enableCommand("MathType"); + trackChangesEditing.enableCommand("ChemType"); + + // Adds custom label replacing the default 'mathml'. + // Handles both singular and plural forms. + trackChangesEditing.descriptionFactory.registerElementLabel( + "mathml", + quantity => (quantity > 1 ? quantity + ' ' : '') + + StringManager.get(quantity > 1 ? "formulas" : "formula", integration.getLanguage()), + ); + } + } }