[FIX] web_editor: cursor position wrong after link in safari
Before this commit: For the safari browser, when typing any URL and pressing space, and continuing typing, the cursor jumps before the URL. After this commit: Inserting an element into a range clears the selection in Safari. Hence, use the cloned range to reselect it and now the cursor position remains at the end of the URL. Task-3089091 closes odoo/odoo#114192 X-original-commit: fa532d1391aed313a9ea13ac8a4ab9df31c313e3 Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user