[FIX] web_editor: properly apply alignment to links

When the selection was in a link, the alignment buttons didn't work.
That is because they are supposed to align the parent paragraph, which
is temporarily in a contenteditable=false context when the selection is
in a link. This restores the context before applying an editor command,
and restores it afterwards.

task-3083748

X-original-commit: 0a4eb266b198e5e02a3325d063d07c0dd8af0148
Part-of: odoo/odoo#107155
This commit is contained in:
Antoine Guenet
2022-12-05 10:07:52 +01:00
parent f48056fd32
commit c94c19cc3c
@@ -1664,6 +1664,7 @@ export class OdooEditor extends EventTarget {
this._stopContenteditable();
this._fixLinkMutatedElements = {
link,
wasContenteditableTrue: [...editableChildren],
wasContenteditableFalse: [],
wasContenteditableNull: [],
@@ -2064,7 +2065,19 @@ export class OdooEditor extends EventTarget {
}
}
if (editorCommands[method]) {
return editorCommands[method](this, ...args);
// Make sure to restore the content editable before applying an
// editor command, as it might have been temporarily disabled for
// browser behaviors which should not concern editor commands.
const link = this._fixLinkMutatedElements && this._fixLinkMutatedElements.link;
if (this._fixLinkMutatedElements) {
this.resetContenteditableLink();
this._activateContenteditable();
}
const returnValue = editorCommands[method](this, ...args);
if (link) {
this.setContenteditableLink(link);
}
return returnValue;
}
if (method.startsWith('justify')) {
const mode = method.split('justify').join('').toLocaleLowerCase();