[FIX] web_editor: check if closestElement returns element
`getInSelection` had a check that depended on `closestElement` returning an element (and not `undefined` or `null`). closes odoo/odoo#107061 X-original-commit: 0eeff8266ab1c3bdd15d4587aaf83e299811c3fa Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -1391,13 +1391,17 @@ export function containsUnremovable(node) {
|
||||
export function getInSelection(document, selector) {
|
||||
const selection = document.getSelection();
|
||||
const range = selection && !!selection.rangeCount && selection.getRangeAt(0);
|
||||
return (
|
||||
range &&
|
||||
(closestElement(range.startContainer, selector) ||
|
||||
[...closestElement(range.commonAncestorContainer).querySelectorAll(selector)].find(
|
||||
if (range) {
|
||||
const selectorInStartAncestors = closestElement(range.startContainer, selector);
|
||||
if (selectorInStartAncestors) {
|
||||
return selectorInStartAncestors;
|
||||
} else {
|
||||
const commonElementAncestor = closestElement(range.commonAncestorContainer);
|
||||
return commonElementAncestor && [...commonElementAncestor.querySelectorAll(selector)].find(
|
||||
node => range.intersectsNode(node),
|
||||
))
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user