[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) <dmo@odoo.com>
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user