From d80f7a3b73d300e5f9964518f4b2f9baafdd463a Mon Sep 17 00:00:00 2001 From: David Monjoie Date: Mon, 29 Aug 2022 14:57:15 +0000 Subject: [PATCH] [FIX] web_editor: fix alignment buttons not working These are buttons that happen to be inside dropdowns so the preventDefault must be done in that case otherwise the selection of the user is lost and the edition command cannot work. Steps to reproduce: - Select some text - Try to use the justify buttons that are inside the text alignment dropdown in the toolbar task-id 2964314 closes odoo/odoo#99300 X-original-commit: 8a124a9342fc0f7091b78b45d9b7fe13db472927 Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/wysiwyg/wysiwyg.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js index 071f2c871c5..76f45be35d1 100644 --- a/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js +++ b/addons/web_editor/static/src/js/wysiwyg/wysiwyg.js @@ -1359,9 +1359,15 @@ const Wysiwyg = Widget.extend({ }, _configureToolbar: function (options) { const $toolbar = this.toolbar.$el; + // Prevent selection loss when interacting with the toolbar buttons. $toolbar.find('.btn-group').on('mousedown', e => { - // Do not prevent events on popovers. - if (!e.target.closest('.dropdown-menu')) { + if ( + // Prevent when clicking on btn-group but not on dropdown items. + !e.target.closest('.dropdown-menu') || + // Unless they have a data-call in which case there is an editor + // command that is bound to it so we need to preventDefault. + e.target.closest('.btn') && e.target.closest('.btn').getAttribute('data-call') + ) { e.preventDefault(); } });