diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js index 5149097a760..7d772d10a82 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/OdooEditor.js @@ -4204,6 +4204,9 @@ export class OdooEditor extends EventTarget { * @param {int} length */ _createLinkWithUrlInTextNode(textNode, url, index, length) { + const selection = this.document.getSelection(); + const cloneRange = selection.getRangeAt(0).cloneRange(); + const link = this.document.createElement('a'); link.setAttribute('href', url); for (const [param, value] of Object.entries(this.options.defaultLinkAttributes)) { @@ -4214,6 +4217,10 @@ export class OdooEditor extends EventTarget { range.setEnd(textNode, index + length); link.appendChild(range.extractContents()); range.insertNode(link); + // Inserting an element into a range clears the selection in Safari + // Hence, use the cloned range to reselect it. + selection.removeAllRanges(); + selection.addRange(cloneRange); } /**