From de2c7cff6fbfb39697b602035fea1ff1cd3c08cf Mon Sep 17 00:00:00 2001 From: "Emilien Durieu (edu)" Date: Thu, 5 Aug 2021 13:57:45 +0000 Subject: [PATCH] [FIX] web_editor: prevent double space insertion The auto-link making feature would insert two spaces when the user would try to add one space. It is no longer the case. Some selection management with the link making has been fixed as well. task-2584101 --- .../static/lib/odoo-editor/src/OdooEditor.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) 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 f3b9c032336..87257f85018 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -1685,12 +1685,11 @@ export class OdooEditor extends EventTarget { if ( ev.data.includes(' ') && selection && - selection.anchorNode && - !this.commandBar._active + selection.anchorNode + && (!this.commandBar._active || + this.commandBar._currentOpenOptions.closeOnSpace !== true) ) { - ev.preventDefault(); this._convertUrlInElement(closestElement(selection.anchorNode)); - this.execCommand('insertText', ev.data); } this.sanitize(); this.historyStep(); @@ -2093,14 +2092,16 @@ export class OdooEditor extends EventTarget { * @param {int} length */ _createLinkWithUrlInTextNode(textNode, url, index, length) { - setCursor(textNode, index, textNode, index + length); - this.document.execCommand('createLink', false, url); - const sel = this.document.getSelection(); - const link = closestElement(sel.anchorNode, 'a'); + const link = this.document.createElement('a') + link.setAttribute('href', url) for (const [param, value] of Object.entries(this.options.defaultLinkAttributes)) { link.setAttribute(param, `${value}`); } - sel.collapseToEnd(); + const range = this.document.createRange() + range.setStart(textNode, index) + range.setEnd(textNode, index+length) + link.appendChild(range.extractContents()) + range.insertNode(link) } /**