Skip to content

Commit 15ac687

Browse files
feat: track changes feature compatibility
1 parent dec699c commit 15ac687

File tree

9 files changed

+111
-21
lines changed

9 files changed

+111
-21
lines changed

packages/ckeditor5/dist/browser/index.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11267,7 +11267,9 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
1126711267
// Remove selection
1126811268
if (!viewSelection.isCollapsed) {
1126911269
for (const range of viewSelection.getRanges()){
11270-
writer.remove(this.editorObject.editing.mapper.toModelRange(range));
11270+
const modelRange = this.editorObject.editing.mapper.toModelRange(range);
11271+
const modelSelection = this.editorObject.model.createSelection(modelRange);
11272+
this.editorObject.model.deleteContent(modelSelection);
1127111273
}
1127211274
}
1127311275
// Set carret after the formula
@@ -11283,7 +11285,7 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
1128311285
if (mathml) {
1128411286
this.editorObject.model.insertObject(modelElementNew, position);
1128511287
}
11286-
writer.remove(modelElementOld);
11288+
this.editorObject.model.deleteContent(this.editorObject.model.createSelection(modelElementOld, 'on'));
1128711289
}
1128811290
// eslint-disable-next-line consistent-return
1128911291
return modelElementNew;
@@ -11354,7 +11356,8 @@ delete Array.prototype.__class__; // @codingStandardsIgnoreEnd
1135411356
range = writer.createRange(startPosition, endPosition);
1135511357
}
1135611358
}
11357-
writer.remove(range);
11359+
const modelSelection = this.editorObject.model.createSelection(range);
11360+
this.editorObject.model.deleteContent(modelSelection);
1135811361
writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
1135911362
});
1136011363
} else {
@@ -11495,7 +11498,9 @@ class MathType extends Plugin {
1149511498
const integration = this._addIntegration();
1149611499
currentInstance = integration;
1149711500
// Add the MathType and ChemType commands to the editor
11498-
this._addCommands();
11501+
this._addCommands(integration);
11502+
// Add the track changes feature integration
11503+
this._addTrackChangesIntegration(integration);
1149911504
// Add the buttons for MathType and ChemType
1150011505
this._addViews(integration);
1150111506
// Registers the <mathml> element in the schema
@@ -11935,6 +11940,18 @@ class MathType extends Plugin {
1193511940
Latex
1193611941
};
1193711942
}
11943+
_addTrackChangesIntegration(integration) {
11944+
const { editor } = this;
11945+
if (editor.plugins.has("TrackChangesEditing")) {
11946+
const trackChangesEditing = editor.plugins.get("TrackChangesEditing");
11947+
// Makes MathType and ChemType buttons available when editor is in the track changes mode
11948+
trackChangesEditing.enableCommand("MathType");
11949+
trackChangesEditing.enableCommand("ChemType");
11950+
// Adds custom label replacing the default 'mathml'.
11951+
// Handles both singular and plural forms.
11952+
trackChangesEditing.descriptionFactory.registerElementLabel("mathml", (quantity)=>(quantity > 1 ? quantity + ' ' : '') + StringManager.get(quantity > 1 ? "formulas" : "formula", integration.getLanguage()));
11953+
}
11954+
}
1193811955
}
1193911956

1194011957
export { CKEditor5Integration, ChemTypeCommand, MathTypeCommand, MathType as default };

packages/ckeditor5/dist/browser/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ckeditor5/dist/browser/index.umd.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11269,7 +11269,9 @@
1126911269
// Remove selection
1127011270
if (!viewSelection.isCollapsed) {
1127111271
for (const range of viewSelection.getRanges()){
11272-
writer.remove(this.editorObject.editing.mapper.toModelRange(range));
11272+
const modelRange = this.editorObject.editing.mapper.toModelRange(range);
11273+
const modelSelection = this.editorObject.model.createSelection(modelRange);
11274+
this.editorObject.model.deleteContent(modelSelection);
1127311275
}
1127411276
}
1127511277
// Set carret after the formula
@@ -11285,7 +11287,7 @@
1128511287
if (mathml) {
1128611288
this.editorObject.model.insertObject(modelElementNew, position);
1128711289
}
11288-
writer.remove(modelElementOld);
11290+
this.editorObject.model.deleteContent(this.editorObject.model.createSelection(modelElementOld, 'on'));
1128911291
}
1129011292
// eslint-disable-next-line consistent-return
1129111293
return modelElementNew;
@@ -11356,7 +11358,8 @@
1135611358
range = writer.createRange(startPosition, endPosition);
1135711359
}
1135811360
}
11359-
writer.remove(range);
11361+
const modelSelection = this.editorObject.model.createSelection(range);
11362+
this.editorObject.model.deleteContent(modelSelection);
1136011363
writer.insertText(`$$${returnObject.latex}$$`, startNode.getAttributes(), startPosition);
1136111364
});
1136211365
} else {
@@ -11497,7 +11500,9 @@
1149711500
const integration = this._addIntegration();
1149811501
currentInstance = integration;
1149911502
// Add the MathType and ChemType commands to the editor
11500-
this._addCommands();
11503+
this._addCommands(integration);
11504+
// Add the track changes feature integration
11505+
this._addTrackChangesIntegration(integration);
1150111506
// Add the buttons for MathType and ChemType
1150211507
this._addViews(integration);
1150311508
// Registers the <mathml> element in the schema
@@ -11937,6 +11942,18 @@
1193711942
Latex
1193811943
};
1193911944
}
11945+
_addTrackChangesIntegration(integration) {
11946+
const { editor } = this;
11947+
if (editor.plugins.has("TrackChangesEditing")) {
11948+
const trackChangesEditing = editor.plugins.get("TrackChangesEditing");
11949+
// Makes MathType and ChemType buttons available when editor is in the track changes mode
11950+
trackChangesEditing.enableCommand("MathType");
11951+
trackChangesEditing.enableCommand("ChemType");
11952+
// Adds custom label replacing the default 'mathml'.
11953+
// Handles both singular and plural forms.
11954+
trackChangesEditing.descriptionFactory.registerElementLabel("mathml", (quantity)=>(quantity > 1 ? quantity + ' ' : '') + StringManager.get(quantity > 1 ? "formulas" : "formula", integration.getLanguage()));
11955+
}
11956+
}
1194011957
}
1194111958

1194211959
exports.CKEditor5Integration = CKEditor5Integration;

packages/ckeditor5/dist/browser/index.umd.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ckeditor5/dist/index.js

Lines changed: 21 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/ckeditor5/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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
}

packages/res/demos/index.html

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,19 @@ <h1 class="header_title" id="header_title_name">&nbsp;</h1>
99
</ul>
1010
</div>
1111
</header>
12-
<div id="editor">
13-
<!-- Default content of the editor div is loaded through imports.js -->
12+
<div class="main-container">
13+
<div class="editor-container editor-container--classic-editor editor-container--include-annotations" id="editor-container">
14+
<div class="editor-container__editor-wrapper">
15+
<div class="editor-container__editor">
16+
<div id="editor">
17+
<!-- Default content of the editor div is loaded through imports.js -->
18+
</div>
19+
</div>
20+
<div class="editor-container__sidebar">
21+
<div id="editor-annotations"></div>
22+
</div>
23+
</div>
24+
</div>
1425
</div>
1526
<div class="actions">
1627
<a class="btn btn_update-distances btn_update-display" id="btn_update" href="#" data-testid="demo-update-button"

0 commit comments

Comments
 (0)