[FIX] web_editor: check if no selection in _handleSelectionInTable

Before this commit, if there were no selection in
`_handleSelectionInTable` because the document was removed (in case the
document was in a removed iframe), the method would crash.

task-3052658

closes odoo/odoo#112908

X-original-commit: 8e23a4191730d5512c9de81c23f8e4e88e99ddb1
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Nicolas Bayet
2023-02-16 17:57:20 +01:00
parent 5321ed9120
commit de4bb25464
@@ -2230,7 +2230,8 @@ export class OdooEditor extends EventTarget {
*/
_handleSelectionInTable(ev=undefined) {
const selection = this.document.getSelection();
const anchorNode = selection.anchorNode;
// Selection could be gone if the document comes from an iframe that has been removed.
const anchorNode = selection && selection.getRangeAt(0) && selection.anchorNode;
if (anchorNode && (closestElement(anchorNode, '[data-oe-protected="true"]') || !ancestors(anchorNode).includes(this.editable))) {
return false;
}