[FIX] web_editor: properly handle exec toolbar command after input click

When clicking on an input in the toolbar, the selection was lost and
the commands could not be executed. This restores the latest selection
in the editable in these cases.

Part-of: odoo/odoo#119972
This commit is contained in:
Antoine Guenet
2023-06-16 18:21:46 +02:00
parent 2d5194f8a3
commit c7a5ed99ba
@@ -1852,13 +1852,13 @@ export class OdooEditor extends EventTarget {
bindExecCommand(element) {
for (const buttonEl of element.querySelectorAll('[data-call]')) {
buttonEl.addEventListener('click', ev => {
const sel = this.document.getSelection();
if (sel.anchorNode && ancestors(sel.anchorNode).includes(this.editable)) {
this.execCommand(buttonEl.dataset.call, buttonEl.dataset.arg1);
ev.preventDefault();
this._updateToolbar();
if (!this.isSelectionInEditable()) {
this.historyResetLatestComputedSelection(true);
}
this.execCommand(buttonEl.dataset.call, buttonEl.dataset.arg1);
ev.preventDefault();
this._updateToolbar();
});
}
}