[FIX] web_editor: enter at A edge no dup link

In the editor, when you write a letter at the end or beginning of a link
it is written outside the link. But if you press "Enter", we get on a
newline with an empty link duplicated on the new line.

This is caused by the custom code handling "Enter" keypress.

With this changeset, in this situation we place the range just before
the beginning or after the end of a link.

opw-1724606
opw-2042097
closes #35188

Signed-off-by: Nicolas Lempereur (nle) <nle@odoo.com>
This commit is contained in:
Nicolas Lempereur
2019-07-26 08:33:27 +00:00
parent 30a9120346
commit 53ef25284f
@@ -1181,6 +1181,20 @@ $.summernote.pluginEvents.enter = function (event, editor, layoutInfo) {
var br = $("<br/>")[0];
// set selection outside of A if range is at beginning or end
var elem = dom.isBR(elem) ? elem.parentNode : dom.node(r.sc);
if (elem.tagName === "A") {
if (r.so === 0 && dom.firstChild(elem) === r.sc) {
r.ec = r.sc = dom.hasContentBefore(elem) || $(dom.createText('')).insertBefore(elem)[0];
r.eo = r.so = dom.nodeLength(r.sc);
r.select();
} else if (dom.nodeLength(r.sc) === r.so && dom.lastChild(elem) === r.sc) {
r.ec = r.sc = dom.hasContentAfter(elem) || dom.insertAfter(dom.createText(''), elem);
r.eo = r.so = 0;
r.select();
}
}
var node;
var $node;
var $clone;