[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) <dmo@odoo.com>
This commit is contained in:
Sébastien Geelen (sge)
2023-06-07 18:01:13 +02:00
parent 0dfed1b18b
commit dd7a50db06
@@ -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 <t> element.
this.wysiwyg.focus();
let dynamicPlaceholder = "object." + chain.join('.');
dynamicPlaceholder += defaultValue && defaultValue !== '' ? ` or '''${defaultValue}'''` : '';
const t = document.createElement('T');