diff options
| author | Nicolas Lempereur <nle@odoo.com> | 2018-06-11 15:26:16 +0200 |
|---|---|---|
| committer | Nicolas Lempereur <nle@odoo.com> | 2018-06-13 16:20:40 +0200 |
| commit | c4ddf55880b7aa83580aa8ab312ba71f093a7587 (patch) | |
| tree | fd7693d86ed121d817a86fe953789c53d09c17ad /addons/web_editor/static/src/js/widgets.js | |
| parent | a8dd1de5c466b64351d54536ac0529d2a744cf4d (diff) | |
[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
Diffstat (limited to 'addons/web_editor/static/src/js/widgets.js')
| -rw-r--r-- | addons/web_editor/static/src/js/widgets.js | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/addons/web_editor/static/src/js/widgets.js b/addons/web_editor/static/src/js/widgets.js index f23e196997a..b7e21996e45 100644 --- a/addons/web_editor/static/src/js/widgets.js +++ b/addons/web_editor/static/src/js/widgets.js @@ -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) { |
