[FIX] web_editor: apply original element attributes on toggle list

When converting an element to a list element, we didn't preserve that
original element's attributes. As a consequence the text direction was
lost.

closes odoo/odoo#90247

X-original-commit: 0731ff677491d80540fa2ffc645fd2b471a9f61c
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
This commit is contained in:
Antoine Guenet
2022-05-02 07:43:55 +02:00
parent 618d5bc3ca
commit 53aba047ce
2 changed files with 11 additions and 0 deletions
@@ -49,6 +49,7 @@ HTMLLIElement.prototype.oShiftTab = function () {
return li;
} else {
const ul = li.parentNode;
const dir = ul.getAttribute('dir');
let p;
while (li.firstChild) {
if (isBlock(li.firstChild)) {
@@ -56,6 +57,10 @@ HTMLLIElement.prototype.oShiftTab = function () {
ul.after(li.firstChild);
} else {
p = p || document.createElement('P');
if (dir) {
p.setAttribute('dir', dir);
p.style.setProperty('text-align', ul.style.getPropertyValue('text-align'));
}
p.append(li.firstChild);
}
}
@@ -30,6 +30,9 @@ HTMLElement.prototype.oToggleList = function (offset, mode = 'UL') {
restoreCursor();
} else {
const list = insertListAfter(this, mode, [this]);
for (const attribute of this.attributes) {
list.setAttribute(attribute.name, attribute.value);
}
restoreCursor(new Map([[this, list.firstElementChild]]));
}
};
@@ -37,6 +40,9 @@ HTMLElement.prototype.oToggleList = function (offset, mode = 'UL') {
HTMLParagraphElement.prototype.oToggleList = function (offset, mode = 'UL') {
const restoreCursor = preserveCursor(this.ownerDocument);
const list = insertListAfter(this, mode, [[...this.childNodes]]);
for (const attribute of this.attributes) {
list.setAttribute(attribute.name, attribute.value);
}
this.remove();
restoreCursor(new Map([[this, list.firstChild]]));