From c3085b0011005492268341d8c1dd856d6cb4596e Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 3 Mar 2023 15:03:19 +0000 Subject: [PATCH] [REF] web_editor: remove `clearEmpty` This removes the `clearEmpty` util which was only used in the `enter` command. closes odoo/odoo#114178 Signed-off-by: David Monjoie (dmo) --- .../editor/odoo-editor/src/commands/enter.js | 25 ++++++++++++------- .../js/editor/odoo-editor/src/utils/utils.js | 14 ----------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/enter.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/enter.js index ac31412db50..d75af974359 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/enter.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/enter.js @@ -3,7 +3,6 @@ import { UNBREAKABLE_ROLLBACK_CODE } from '../utils/constants.js'; import { childNodeIndex, - clearEmpty, fillEmpty, isBlock, isUnbreakable, @@ -44,7 +43,7 @@ HTMLElement.prototype.oEnter = function (offset, firstSplit = true) { } // First split the node in two and move half the children in the clone. - const splitEl = this.cloneNode(false); + let splitEl = this.cloneNode(false); while (offset < this.childNodes.length) { splitEl.appendChild(this.childNodes[offset]); } @@ -74,14 +73,22 @@ HTMLElement.prototype.oEnter = function (offset, firstSplit = true) { if (firstSplit && didSplit) { restore(); - fillEmpty(clearEmpty(this)); + let node = this; + while (!isBlock(node) && !isVisible(node)) { + const toRemove = node; + node = node.parentNode; + toRemove.remove(); + } + fillEmpty(node); fillEmpty(splitEl); - - const focusToElement = - splitEl.nodeType === Node.ELEMENT_NODE && splitEl.tagName === 'A' - ? clearEmpty(splitEl) - : splitEl; - setCursorStart(focusToElement); + if (splitEl.tagName === 'A') { + while (!isBlock(splitEl) && !isVisible(splitEl)) { + const toRemove = splitEl; + splitEl = splitEl.parentNode; + toRemove.remove(); + } + } + setCursorStart(splitEl); } return splitEl; }; diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 5412ccf36d4..9041fe55814 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -1913,20 +1913,6 @@ export function insertAndSelectZws(selection) { selection.getRangeAt(0).selectNode(zws); return zws; } -/** - * Removes the given node if invisible and all its invisible ancestors. - * - * @param {Node} node - * @returns {Node} the first visible ancestor of node (or itself) - */ -export function clearEmpty(node) { - while (!isBlock(node) && !isVisible(node)) { - const toRemove = node; - node = node.parentNode; - toRemove.remove(); - } - return node; -} export function setTagName(el, newTagName) { if (el.tagName === newTagName) {