[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
This commit is contained in:
Emilien Durieu (edu)
2021-08-10 07:56:35 +00:00
parent 9c9b7d7c37
commit de2c7cff6f
@@ -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)
}
/**