From c4ddf55880b7aa83580aa8ab312ba71f093a7587 Mon Sep 17 00:00:00 2001 From: Nicolas Lempereur Date: Mon, 11 Jun 2018 15:26:16 +0200 Subject: [FIX] web_editor: link don't duplicate child text If we applied a link eg. on: ``` hello world ``` The system actually gets the "label": hello worldworld because there is 3 nodes: text node: hello element node: `world` text node: world Also since "hello worldworld" is different than "hello world", instead of just keeping existing nodes and adding the link, the system would replace the selected range by: `hello worldworld' instead of: `hello world` This commit ignores element nodes when creating a new link, since when getting the label of the link from the selection, only the text nodes insides the element nodes have any interest. There was a second issue because if we had: ``` world! ``` and tried to put a link over "world!", the code would decide: "world" is inside a link so we will just update that link. Thus we would get: ``` world!! ``` instead of: ``` world! ``` opw-1848351 closes #25187 --- addons/web_editor/static/lib/summernote/src/js/module/Editor.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'addons/web_editor/static/lib/summernote/src/js/module') diff --git a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js b/addons/web_editor/static/lib/summernote/src/js/module/Editor.js index a30ee9c18c8..3ae8f60db7d 100644 --- a/addons/web_editor/static/lib/summernote/src/js/module/Editor.js +++ b/addons/web_editor/static/lib/summernote/src/js/module/Editor.js @@ -629,9 +629,9 @@ define([ } var anchors = []; - // ODOO: adding this branch to modify existing anchor + // ODOO: adding this branch to modify existing anchor if it fully contains the range var ancestor_anchor = dom.ancestor(rng.sc, dom.isAnchor); - if(ancestor_anchor) { + if(ancestor_anchor && ancestor_anchor === dom.ancestor(rng.ec, dom.isAnchor)) { anchors.push($(ancestor_anchor).html(linkText).get(0)); } else if (isTextChanged) { // Create a new link when text changed. -- cgit v1.2.3