[FIX] web_editor: apply format in classless unbreakable inline

When applying a format in an unbreakable inline (without a class), the
format was immediately rolled back as we tried to remove split the
unbreakable in order to remove its style.

task-3768157

closes odoo/odoo#159110

X-original-commit: 78e809c18db7bd520ccf706b2504139248fbd0ff
Signed-off-by: David Monjoie (dmo) <dmo@odoo.com>
Signed-off-by: Antoine Guenet (age) <age@odoo.com>
This commit is contained in:
Antoine Guenet
2024-03-25 16:26:59 +00:00
parent 7d66b910c4
commit 421f1f693b
2 changed files with 20 additions and 2 deletions
@@ -1119,8 +1119,12 @@ export const formatSelection = (editor, formatName, {applyStyle, formatProps} =
// Remove the format on all inline ancestors until a block or an element
// with a class that is not related to font size (in case the formatting
// comes from the class).
while (parentNode && (!isBlock(parentNode) && (parentNode.classList.length === 0 ||
[...parentNode.classList].every(cls => FONT_SIZE_CLASSES.includes(cls))))) {
while (
parentNode && !isBlock(parentNode) &&
!isUnbreakable(parentNode) && !isUnbreakable(currentNode) &&
(parentNode.classList.length === 0 ||
[...parentNode.classList].every(cls => FONT_SIZE_CLASSES.includes(cls)))
) {
const isUselessZws = parentNode.tagName === 'SPAN' &&
parentNode.hasAttribute('data-oe-zws-empty-inline') &&
parentNode.getAttributeNames().length === 1;
@@ -882,6 +882,20 @@ describe('Format', () => {
contentAfter: '<table><tbody><tr><td><h1><span style="font-size: 18px;">[]<br></span></h1></td><td><h1><span style="font-size: 18px;"><br></span></h1></td></tr><tr><td><h1><br></h1></td><td><h1><br></h1></td></tr></tbody></table>',
});
});
it('should apply font size in unbreakable span with class', async () => {
await testEditor(BasicEditor, {
contentBefore: `<h1><span class="oe_unbreakable">some [text]</span></h1>`,
stepFunction: setFontSize('18px'),
contentAfter: `<h1><span class="oe_unbreakable">some <span style="font-size: 18px;">[text]</span></span></h1>`,
});
});
it('should apply font size in unbreakable span without class', async () => {
await testEditor(BasicEditor, {
contentBefore: `<h1><span t="unbreakable">some [text]</span></h1>`,
stepFunction: setFontSize('18px'),
contentAfter: `<h1><span t="unbreakable">some <span style="font-size: 18px;">[text]</span></span></h1>`,
});
});
});
it('should add style to a span parent of an inline', async () => {