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;