From dd7a50db0688c1f65ee4fc686bb25e12fc571e84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Geelen=20=28sge=29?= Date: Wed, 7 Jun 2023 08:19:24 +0000 Subject: [PATCH] [FIX] web_editor: ensure dynamic placeholder focus When inserting a dynamic placeholder in the editable document we need to ensure the said document currently hold the focus and have an active selection range. This was previously handle by the `onDynamicPlaceholderClose()` method which used to be called before `onDynamicPlaceholderValidate()`. This seems to have changed from 16.1 to 16.2. In order to fix the problem and ensure the focus in any situation, we add a `wysiwyg.focus()` call at the beginning of the validate method. task-3222474 closes odoo/odoo#124149 X-original-commit: 51b992dec0bcdf09fde5e0811699235b590723ee Signed-off-by: David Monjoie (dmo) --- addons/web_editor/static/src/js/backend/html_field.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/addons/web_editor/static/src/js/backend/html_field.js b/addons/web_editor/static/src/js/backend/html_field.js index 8ba88b1e815..e61e07a84aa 100644 --- a/addons/web_editor/static/src/js/backend/html_field.js +++ b/addons/web_editor/static/src/js/backend/html_field.js @@ -368,6 +368,9 @@ export class HtmlField extends Component { } onDynamicPlaceholderValidate(chain, defaultValue) { if (chain) { + // Ensure the focus is in the editable document + // before inserting the element. + this.wysiwyg.focus(); let dynamicPlaceholder = "object." + chain.join('.'); dynamicPlaceholder += defaultValue && defaultValue !== '' ? ` or '''${defaultValue}'''` : ''; const t = document.createElement('T');