From d5ec63cd486ad59e018f554124e8893bfab55756 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Mon, 19 Apr 2021 09:10:58 +0000 Subject: [PATCH] [FIX] web_editor: fix traceback for some CTRL+A cases in mass_mailing closes odoo/odoo#69486 X-original-commit: 22926d0bfca472daad8cebddbc19e6bb3e846904 Signed-off-by: David Monjoie (dmo) --- .../static/src/js/wysiwyg/wysiwyg.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 312647ff1b4..5bbca25a4e9 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -860,13 +860,21 @@ const Wysiwyg = Widget.extend({ if (e && e.key === 'a' && (e.ctrlKey || e.metaKey)) { e.preventDefault(); const selection = this.odooEditor.document.getSelection(); - const deepestParent = + const containerSelector = '#wrap>*, [contenteditable], .oe_structure>*'; + let $deepestParent = selection ? - $(selection.anchorNode).parentsUntil('#wrap>*, [contenteditable], .oe_structure>*').last() : - []; - if(deepestParent.length) { + $(selection.anchorNode).parentsUntil(containerSelector).last() : + $(); + + if ($deepestParent.is('html')) { + // In case we didn't find a suitable container + // we need to restrict the selection inside to the editable area. + $deepestParent = this.$editable.find(containerSelector); + } + + if ($deepestParent.length) { const range = document.createRange(); - range.selectNodeContents(deepestParent.parent()[0]); + range.selectNodeContents($deepestParent.parent()[0]); selection.removeAllRanges(); selection.addRange(range); }