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