From 0a4eb266b198e5e02a3325d063d07c0dd8af0148 Mon Sep 17 00:00:00 2001 From: Antoine Guenet <age@odoo.com> Date: Tue, 29 Nov 2022 11:12:51 +0000 Subject: [PATCH] [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 Part-of: odoo/odoo#106772 --- .../static/lib/odoo-editor/src/OdooEditor.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js index 53c3deebeb00..4be02fafd83d 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -1311,6 +1311,7 @@ export class OdooEditor extends EventTarget { this._stopContenteditable(); this._fixLinkMutatedElements = { + link, wasContenteditableTrue: [...editableChildren], wasContenteditableFalse: [], wasContenteditableNull: [], @@ -1623,7 +1624,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(); -- GitLab