From 538f99ccce90cb1487bd19e38b4bc8310b0677f6 Mon Sep 17 00:00:00 2001 From: Julien Castiaux Date: Wed, 8 May 2019 14:07:55 +0000 Subject: [PATCH] [FIX] web_editor: restoreRange on invalid node In a web editor, add some text, select the text, add a link and immediately discard the link modal. Traceback. The traceback is a DOM `IndexSizeError`, that error is thrown when the boundaries of a DOM Range (`document.createRange`) are outside of the ranged elements. In this context, the error happens because the element is empty and the range has an end bound set to the size of the selected text. Odoo wrap code does some text node split in order to attach the link just on the selected text. If it correctly re-set the underlying structure, it does not update the $(editable) structure used to restore ranges. opw-1981751 closes odoo/odoo#33257 Signed-off-by: Julien Castiaux --- addons/web_editor/static/src/js/widgets/widgets.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/web_editor/static/src/js/widgets/widgets.js b/addons/web_editor/static/src/js/widgets/widgets.js index 7fda9238f34..43bc2e95199 100644 --- a/addons/web_editor/static/src/js/widgets/widgets.js +++ b/addons/web_editor/static/src/js/widgets/widgets.js @@ -1405,6 +1405,7 @@ var LinkDialog = Dialog.extend({ } this.data.range = range.create(sc, so, ec, eo); + $(editable).data("range", this.data.range); this.data.range.select(); } else { nodes = dom.ancestor(sc, dom.isAnchor).childNodes;