From b6cd2ec7ea7fe3df0ed02a9f863fd982433ff00c Mon Sep 17 00:00:00 2001 From: Nicolas Cornaglia Date: Thu, 1 Oct 2026 12:58:24 +0200 Subject: [PATCH 1/2] fix: improve insertion position handling for MathML formulas --- packages/ckeditor5/src/integration.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/ckeditor5/src/integration.js b/packages/ckeditor5/src/integration.js index b8b94129a..13c9d165f 100644 --- a/packages/ckeditor5/src/integration.js +++ b/packages/ckeditor5/src/integration.js @@ -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. */ @@ -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; @@ -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; From 6a7f74be05fde42e9427eaed9b05bf92b9714599 Mon Sep 17 00:00:00 2001 From: Nicolas Cornaglia Date: Mon, 5 Oct 2026 11:56:15 +0200 Subject: [PATCH 2/2] fix: enhance insertion position handling in CKEditor5 integration --- packages/ckeditor5/src/integration.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ckeditor5/src/integration.js b/packages/ckeditor5/src/integration.js index 13c9d165f..d533c1bfd 100644 --- a/packages/ckeditor5/src/integration.js +++ b/packages/ckeditor5/src/integration.js @@ -68,6 +68,12 @@ export default class CKEditor5Integration extends IntegrationModel { addEditorListeners() { const editor = this.editorObject; + editor.listenTo(editor.model.document.selection, "change:range", () => { + if (this.insertionSelection && editor.editing.view.document.isFocused) { + this.insertionSelection = editor.model.createSelection(editor.model.document.selection); + } + }); + if (typeof editor.config.wirislistenersdisabled === "undefined" || !editor.config.wirislistenersdisabled) { this.checkElement(); }