[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) <dmo@odoo.com>
This commit is contained in:
David Monjoie
2022-08-31 18:53:57 +02:00
parent 0ae158bf43
commit d80f7a3b73
@@ -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();
}
});