Skip to content
Snippets Groups Projects
Commit a3ee1764 authored by Sébastien Geelen (sge)'s avatar Sébastien Geelen (sge)
Browse files

[FIX] web_editor: Fix style formating traceback

In some case, when removing format on element with multiple textNode,
the code generate a traceback.

The loops in `toggleFormat` provide a limit element `closestDecorated` to
the `splitAroundUntil` util. However this limit element can be split and
dumped by the format removal. In this case the reference was never encountered
in the DOM by the `splitAroundUntil` code and will bubble all the way to the
`<html>` TAG an try to split it, which generate an error.

We fix it by getting the `closestDecorated` in every loop.

task-2850686

X-original-commit: 2d93345c
Part-of: odoo/odoo#91786
parent cc80572e
No related branches found
No related tags found
No related merge requests found
......@@ -421,12 +421,12 @@ export function toggleFormat(editor, format) {
const {anchorNode, anchorOffset, focusNode, focusOffset} = editor.document.getSelection();
const style = styles[format];
const selectedTextNodes = getSelectedNodes(editor.editable)
.filter(n => n.nodeType === Node.TEXT_NODE && n.nodeValue.trim().length);
.filter(n => n.nodeType === Node.TEXT_NODE && n.nodeValue.length);
const isAlreadyFormatted = style.is(editor.editable);
let changedElements = [];
if (isAlreadyFormatted && style.name === 'textDecorationLine') {
const decoratedPairs = new Set(selectedTextNodes.map(n => [closestElement(n, `[style*="text-decoration-line: ${style.value}"]`), n]));
for (const [closestDecorated, textNode] of decoratedPairs) {
for (const textNode of selectedTextNodes) {
const closestDecorated = closestElement(textNode, `[style*="text-decoration-line: ${style.value}"]`);
if (closestDecorated) {
const splitResult = splitAroundUntil(textNode, closestDecorated);
const decorationToRemove = splitResult[0] || splitResult[1] || closestDecorated;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment