Skip to content

Commit

Permalink
[FIX] web_editor: restoreRange on invalid node
Browse files Browse the repository at this point in the history
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#33257

Signed-off-by: Julien Castiaux <[email protected]>
  • Loading branch information
Julien00859 committed May 9, 2019
1 parent e11bacf commit 538f99c
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions addons/web_editor/static/src/js/widgets/widgets.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 538f99c

Please sign in to comment.