From 7b18d2d27d1fb4db6ae360eadfe05ee8609a91a0 Mon Sep 17 00:00:00 2001 From: ncornaglia-at-wiris Date: Mon, 3 Nov 2025 12:19:01 +0100 Subject: [PATCH 1/2] fix: using textarea for editor, insert formula when clicking on mathtype icon after reloading website. --- packages/ckeditor5/src/integration.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/ckeditor5/src/integration.js b/packages/ckeditor5/src/integration.js index 2fc6bc886..da1094871 100644 --- a/packages/ckeditor5/src/integration.js +++ b/packages/ckeditor5/src/integration.js @@ -244,6 +244,15 @@ export default class CKEditor5Integration extends IntegrationModel { this.editorObject.model.change((writer) => { const { latexRange } = this.core.editionProperties; + // Add null check for latexRange + // This change is needed as when the editor is set in an id of a textarea and not a div, we default to this conditional. + // If this check is not present and we click on the mathtype icon after reloading the page, the equation is not inserted. + if (!latexRange) { + // Fallback to regular MathML insertion if latexRange is not available + this.insertMathml(mathml); + return; + } + const startNode = this.findText(latexRange.startContainer); const endNode = this.findText(latexRange.endContainer); From b602f5f2177f7516270069a21bbfc804f315443a Mon Sep 17 00:00:00 2001 From: Nicolas Cornaglia Date: Mon, 3 Nov 2025 12:36:21 +0100 Subject: [PATCH 2/2] Update packages/ckeditor5/src/integration.js Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- packages/ckeditor5/src/integration.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/ckeditor5/src/integration.js b/packages/ckeditor5/src/integration.js index da1094871..0a0f771d7 100644 --- a/packages/ckeditor5/src/integration.js +++ b/packages/ckeditor5/src/integration.js @@ -244,9 +244,9 @@ export default class CKEditor5Integration extends IntegrationModel { this.editorObject.model.change((writer) => { const { latexRange } = this.core.editionProperties; - // Add null check for latexRange - // This change is needed as when the editor is set in an id of a textarea and not a div, we default to this conditional. - // If this check is not present and we click on the mathtype icon after reloading the page, the equation is not inserted. + // Add null check for latexRange. + // When the editor is initialized in a textarea element, latexRange may not be set on initial load. + // This check ensures formulas can still be inserted by falling back to MathML insertion if latexRange is not available. if (!latexRange) { // Fallback to regular MathML insertion if latexRange is not available this.insertMathml(mathml);