[FIX] web_editor: link don't duplicate child text
If we applied a link eg. on: ``` <span>hello <b>world</b></span> ``` The system actually gets the "label": hello worldworld because there is 3 nodes: text node: hello element node: `<b>world</b>` 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: `<span><a>hello worldworld</a></span>' instead of: `<span><a>hello </a><b><a>world</a></b></span>` 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: ``` <i><a href="hello">world</a></i>! ``` 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: ``` <i><a href="hello">world!</a></i>! ``` instead of: ``` <i><a href="hello">world</a></i><a href="hello">!</a> ``` opw-1848351 closes #25187
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -1025,6 +1025,8 @@ var LinkDialog = Dialog.extend({
|
||||
if (dom.ancestor(nodes[i], dom.isImg)) {
|
||||
this.data.images.push(dom.ancestor(nodes[i], dom.isImg));
|
||||
text += '[IMG]';
|
||||
} else if (!is_link && nodes[i].nodeType === 1) {
|
||||
// just use text nodes from listBetween
|
||||
} else if (!is_link && i===0) {
|
||||
text += nodes[i].textContent.slice(so, Infinity);
|
||||
} else if (!is_link && i===nodes.length-1) {
|
||||
|
||||
Reference in New Issue
Block a user