Skip to content

Commit c846c62

Browse files
authored
feat: Add integration with CKEditor5 track changes feature. (#1125)
1 parent e46dcda commit c846c62

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

packages/ckeditor5/src/integration.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,10 @@ export default class CKEditor5Integration extends IntegrationModel {
170170
// Remove selection
171171
if (!viewSelection.isCollapsed) {
172172
for (const range of viewSelection.getRanges()) {
173-
writer.remove(this.editorObject.editing.mapper.toModelRange(range));
173+
const modelRange = this.editorObject.editing.mapper.toModelRange(range);
174+
const modelSelection = this.editorObject.model.createSelection(modelRange);
175+
176+
this.editorObject.model.deleteContent(modelSelection);
174177
}
175178
}
176179

@@ -189,7 +192,7 @@ export default class CKEditor5Integration extends IntegrationModel {
189192
if (mathml) {
190193
this.editorObject.model.insertObject(modelElementNew, position);
191194
}
192-
writer.remove(modelElementOld);
195+
this.editorObject.model.deleteContent(this.editorObject.model.createSelection(modelElementOld,'on'));
193196
}
194197

195198
// eslint-disable-next-line consistent-return
@@ -280,7 +283,9 @@ export default class CKEditor5Integration extends IntegrationModel {
280283
}
281284
}
282285

283-
writer.remove(range);
286+
const modelSelection = this.editorObject.model.createSelection(range);
287+
288+
this.editorObject.model.deleteContent(modelSelection);
284289
writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
285290
});
286291
} else {

packages/ckeditor5/src/plugin.js

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,10 @@ export default class MathType extends Plugin {
4343
currentInstance = integration;
4444

4545
// Add the MathType and ChemType commands to the editor
46-
this._addCommands();
46+
this._addCommands(integration);
47+
48+
// Add the track changes feature integration
49+
this._addTrackChangesIntegration(integration);
4750

4851
// Add the buttons for MathType and ChemType
4952
this._addViews(integration);
@@ -579,4 +582,24 @@ export default class MathType extends Plugin {
579582
Latex,
580583
};
581584
}
585+
586+
_addTrackChangesIntegration(integration) {
587+
const { editor } = this;
588+
589+
if (editor.plugins.has("TrackChangesEditing")) {
590+
const trackChangesEditing = editor.plugins.get("TrackChangesEditing");
591+
592+
// Makes MathType and ChemType buttons available when editor is in the track changes mode
593+
trackChangesEditing.enableCommand("MathType");
594+
trackChangesEditing.enableCommand("ChemType");
595+
596+
// Adds custom label replacing the default 'mathml'.
597+
// Handles both singular and plural forms.
598+
trackChangesEditing.descriptionFactory.registerElementLabel(
599+
"mathml",
600+
quantity => (quantity > 1 ? quantity + ' ' : '') +
601+
StringManager.get(quantity > 1 ? "formulas" : "formula", integration.getLanguage()),
602+
);
603+
}
604+
}
582605
}

0 commit comments

Comments
 (0)