Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions packages/ckeditor5/src/integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ export default class CKEditor5Integration extends IntegrationModel {
*/
super(ckeditorIntegrationModelProperties);

this.insertionSelection = null;

/**
* Folder name used for the integration inside CKEditor plugins folder.
*/
Expand Down Expand Up @@ -133,6 +135,7 @@ export default class CKEditor5Integration extends IntegrationModel {
openNewFormulaEditor() {
// Store the editor selection as it will be lost upon opening the modal
this.core.editionProperties.selection = this.editorObject.editing.view.document.selection;
this.insertionSelection = this.editorObject.model.createSelection(this.editorObject.model.document.selection);

// Focus on the selected editor when multiple editor instances are present
WirisPlugin.currentInstance = this;
Expand All @@ -146,6 +149,16 @@ export default class CKEditor5Integration extends IntegrationModel {
* @returns {module:engine/model/element~Element} The model element corresponding to the inserted image
*/
insertMathml(mathml) {
const { isNewElement } = this.getCore().editionProperties;
const insertionSelection = this.insertionSelection;
this.insertionSelection = null;

if (isNewElement && insertionSelection) {
this.editorObject.model.change((writer) => {
writer.setSelection(insertionSelection);
});
}

return this.editorObject.model.change((writer) => {
const { isNewElement, temporalImage } = this.getCore().editionProperties;
const selection = this.editorObject.model.document.selection;
Expand Down
Loading