From d85451800f7b6d6404757b40400e3d5e4d25fa55 Mon Sep 17 00:00:00 2001 From: Priyanka Kakadiya Date: Fri, 31 May 2019 09:58:47 +0000 Subject: [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 execute `setEnd` on `Range`, that error is thrown because editable DIV doesn't save old range 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. After this commit, editable div will use newly created range for the element for ex: -> content: test -> selected content "test" when click on link dialog: ec: test , eo: 4, sc: test, so: 0 selected content -> start 0, end 4 -> "test" like this after clicking on discard: ec: null text element, eo: 4, sc: null text element, so: 0 selected content -> ec and sc both are null, so it will throw an error while setting cursor position after applying fix when click on discard: ec: test, eo: 4, sc: test, so: 0 selected content -> start 0, end 4 -> "test" task - 1955863 closes odoo/odoo#33792 Signed-off-by: Nicolas Lempereur (nle) --- addons/web_editor/static/src/js/widgets.js | 1 + 1 file changed, 1 insertion(+) (limited to 'addons/web_editor/static/src') diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index ddf94e147a7..fb66c84cf66 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -1007,6 +1007,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; -- cgit v1.2.3