From ce8076566b6581c0da253ea468cfeab00437ed09 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Tue, 6 Sep 2022 07:24:15 +0000 Subject: [PATCH] [FIX] web_editor: traceback selection null in FF In Firefox only : In some case (editor in page but not visible) the `document.getSelection` sometimes return `null` instead of an empty selection object. We add some check to ensure we avoid unnecessary traceback. task-2971126 closes odoo/odoo#99511 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/editor/odoo-editor/src/utils/utils.js | 2 +- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 747df41e908..940a7ad3865 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 @@ -1128,7 +1128,7 @@ export function containsUnremovable(node) { export function getInSelection(document, selector) { const selection = document.getSelection(); - const range = !!selection.rangeCount && selection.getRangeAt(0); + const range = selection && !!selection.rangeCount && selection.getRangeAt(0); return ( range && (closestElement(range.startContainer, selector) || diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 76f45be35d1..6d61364452c 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1769,7 +1769,7 @@ const Wysiwyg = Widget.extend({ this.toolbar.$el.find('.only_fa').toggleClass('d-none', !$target.is('.fa')); // Hide the create-link button if the selection spans several blocks. const selection = this.odooEditor.document.getSelection(); - const range = selection.rangeCount && selection.getRangeAt(0); + const range = selection && selection.rangeCount && selection.getRangeAt(0); const $rangeContainer = range && $(range.commonAncestorContainer); const spansBlocks = range && !!$rangeContainer.contents().filter((i, node) => isBlock(node)).length; if (!range || spansBlocks) {