[FIX] web_editor: on anchor split, rerange and clean data on getValue

Due to a wrong order of operations, after splitting an anchor (press
ENTER), the range was setting on the first anchor. Now it sets on the
second one (as the code - but not the tests - suggests was supposed to
happen). Tests were adapted to reflect that change.

In tests, after splitting the anchor, `Wysiwyg.getValue` didn't always
properly clean up `data-original-title`. Targetting empty
`data-original-title` attribute instead of `aria-describedby` attribute
should fix that issue.

closes odoo/odoo#30923
This commit is contained in:
Antoine Guenet
2019-02-07 10:20:57 +00:00
parent b1fadbc6c6
commit eea58a3cf8
3 changed files with 13 additions and 13 deletions
@@ -372,14 +372,14 @@ var KeyboardPlugin = AbstractPlugin.extend({
return $(n).hasClass('btn');
});
// Move carret to the new button
range = this.context.invoke('editor.setRange', next.firstChild, 0);
range.select();
// Force content in empty buttons, the carret can be moved there
this.context.invoke('LinkPopover.hide');
this.context.invoke('LinkPopover.fillEmptyLink', next, true);
this.context.invoke('LinkPopover.fillEmptyLink', btn, true);
// Move carret to the new button
range = this.context.invoke('editor.setRange', next.firstChild, 0);
range.select();
} else {
range = this.context.invoke('editor.setRange', point.node, point.offset);
range.normalize().select();
@@ -200,6 +200,7 @@ var Wysiwyg = Widget.extend({
$editable.find('[style=""]').removeAttr('style');
$editable.find('[title=""]').removeAttr('title');
$editable.find('[alt=""]').removeAttr('alt');
$editable.find('[data-original-title=""]').removeAttr('data-original-title');
$editable.find('a.o_image, span.fa, i.fa').html('');
$editable.find('[aria-describedby]').removeAttr('aria-describedby').removeAttr('data-original-title');
@@ -1665,9 +1665,9 @@ var keyboardTestsEnter = [{
key: 'a',
}],
test: {
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">&#8203;a&#8203;</a><a class=\"btn\" href=\"#\">dom to edit</a></div>",
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">Label</a><a class=\"btn\" href=\"#\">&#8203;adom to edit&#8203;</a></div>",
// split button has no text so the placeholder text is selected then replaced by 'a'
start: "a:contents()[0]->2",
start: "a:eq(1):contents()[0]->2",
},
},
{
@@ -1680,9 +1680,9 @@ var keyboardTestsEnter = [{
key: 'a',
}],
test: {
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">&#8203;a&#8203;</a><a class=\"btn\" href=\"#\">dom to edit</a></div>",
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">Label</a><a class=\"btn\" href=\"#\">&#8203;adom to edit&#8203;</a></div>",
// split button has no text so the placeholder text is selected then replaced by 'a'
start: "a:contents()[0]->2",
start: "a:eq(1):contents()[0]->2",
},
},
{
@@ -1767,9 +1767,9 @@ var keyboardTestsEnter = [{
key: 'a',
}],
test: {
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">&#8203;a&#8203;</a><a class=\"btn\" href=\"#\">Label</a></div>",
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">Label</a><a class=\"btn\" href=\"#\">&#8203;a&#8203;</a></div>",
// Removing all text in a link replaces that text with "Label"
start: "a:contents()[0]->2",
start: "a:eq(1):contents()[0]->2",
},
},
{
@@ -1781,9 +1781,8 @@ var keyboardTestsEnter = [{
key: 'ENTER',
}],
test: {
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">&#8203;Label&#8203;</a><a class=\"btn\" href=\"#\">ot to edit</a></div>",
start: "a:contents()[0]->1",
end: "a:contents()[0]->6",
content: "<div class=\"unbreakable\"><a class=\"btn\" href=\"#\">Label</a><a class=\"btn\" href=\"#\">&#8203;ot to edit&#8203;</a></div>",
start: "a:eq(1):contents()[0]->1",
},
},
];