From ceb184782f841d955baaf58b8b9ddff12c0a4f45 Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Mon, 20 Oct 2025 13:09:43 +0200 Subject: [PATCH 1/2] :bug: Fix text editor paste inline/paragraph --- .../src/editor/controllers/SelectionController.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/frontend/text-editor/src/editor/controllers/SelectionController.js b/frontend/text-editor/src/editor/controllers/SelectionController.js index 7864990808..1c69c1eef2 100644 --- a/frontend/text-editor/src/editor/controllers/SelectionController.js +++ b/frontend/text-editor/src/editor/controllers/SelectionController.js @@ -1047,6 +1047,17 @@ export class SelectionController extends EventTarget { return isParagraphEnd(this.focusNode, this.focusOffset); } + #getFragmentInlineTextNode(fragment) { + if (isInline(fragment.firstElementChild.lastChild)) { + return fragment.firstElementChild.firstElementChild.lastChild; + } + return fragment.firstElementChild.lastChild; + } + + #getFragmentParagraphTextNode(fragment) { + return fragment.lastElementChild.lastElementChild.lastChild; + } + /** * Insert pasted fragment. * @@ -1071,7 +1082,7 @@ export class SelectionController extends EventTarget { } return this.collapse(collapseNode, collapseNode.nodeValue.length); } - const collapseNode = fragment.lastElementChild.lastElementChild.firstChild; + const collapseNode = this.#getFragmentParagraphTextNode(fragment); if (this.isParagraphStart) { const a = fragment.lastElementChild; const b = this.focusParagraph; From 7f6af6179bc0255001db891ec6407aa307ed92ea Mon Sep 17 00:00:00 2001 From: Aitor Moreno Date: Tue, 21 Oct 2025 09:34:41 +0200 Subject: [PATCH 2/2] :bug: Fix paste when collpaseNode is a br --- .../text-editor/src/editor/controllers/SelectionController.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/frontend/text-editor/src/editor/controllers/SelectionController.js b/frontend/text-editor/src/editor/controllers/SelectionController.js index 1c69c1eef2..934ef82f3f 100644 --- a/frontend/text-editor/src/editor/controllers/SelectionController.js +++ b/frontend/text-editor/src/editor/controllers/SelectionController.js @@ -1101,6 +1101,9 @@ export class SelectionController extends EventTarget { ); this.focusParagraph.after(fragment, newParagraph); } + if (isLineBreak(collapseNode)) { + return this.collapse(collapseNode, 0); + } return this.collapse(collapseNode, collapseNode.nodeValue.length); }