From e2b55d814bab2df1220d710cd93628bbc5d5dfc1 Mon Sep 17 00:00:00 2001 From: Elena Torro Date: Wed, 9 Jul 2025 11:39:16 +0200 Subject: [PATCH] :bug: Fix select all deletion error on Firefox --- .../src/editor/content/dom/Editor.js | 26 +++++++++++++++++++ .../src/editor/content/dom/TextNode.js | 2 ++ .../editor/controllers/SelectionController.js | 1 + 3 files changed, 29 insertions(+) create mode 100644 frontend/text-editor/src/editor/content/dom/Editor.js diff --git a/frontend/text-editor/src/editor/content/dom/Editor.js b/frontend/text-editor/src/editor/content/dom/Editor.js new file mode 100644 index 0000000000..3070d4ed51 --- /dev/null +++ b/frontend/text-editor/src/editor/content/dom/Editor.js @@ -0,0 +1,26 @@ +/** + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * Copyright (c) KALEIDOS INC + */ + +import { isElement } from "./Element.js"; + +export const TAG = "DIV"; +export const TYPE = "editor"; +export const QUERY = `[data-itype="${TYPE}"]`; + +/** + * Returns true if passed node is the editor element. + * + * @param {Node} node + * @returns {boolean} + */ +export function isEditor(node) { + if (!node) return false; + if (!isElement(node, TAG)) return false; + if (node.dataset.itype !== TYPE) return false; + return true; +} diff --git a/frontend/text-editor/src/editor/content/dom/TextNode.js b/frontend/text-editor/src/editor/content/dom/TextNode.js index fff86dbdff..82d918f89b 100644 --- a/frontend/text-editor/src/editor/content/dom/TextNode.js +++ b/frontend/text-editor/src/editor/content/dom/TextNode.js @@ -9,6 +9,7 @@ import { isInline } from "./Inline.js"; import { isLineBreak } from "./LineBreak.js"; import { isParagraph } from "./Paragraph.js"; +import { isEditor } from "./Editor.js"; import { isRoot } from "./Root.js"; /** @@ -60,5 +61,6 @@ export function getClosestTextNode(node) { if (isInline(node)) return node.firstChild; if (isParagraph(node)) return node.firstChild.firstChild; if (isRoot(node)) return node.firstChild.firstChild.firstChild; + if (isEditor(node)) return node.firstChild.firstChild.firstChild.firstChild; throw new Error("Cannot find a text node"); } diff --git a/frontend/text-editor/src/editor/controllers/SelectionController.js b/frontend/text-editor/src/editor/controllers/SelectionController.js index dd01048552..4b4d4d6787 100644 --- a/frontend/text-editor/src/editor/controllers/SelectionController.js +++ b/frontend/text-editor/src/editor/controllers/SelectionController.js @@ -1519,6 +1519,7 @@ export class SelectionController extends EventTarget { const startNode = getClosestTextNode(this.#range.startContainer); const endNode = getClosestTextNode(this.#range.endContainer); + const startOffset = this.#range.startOffset; const endOffset = this.#range.endOffset;