[FIX] web_editor: traceback when changing color

Current behaviour:
When coloring a word multiple colors,
then wanting to re-color it a unified color,
there is a traceback.

Steps to reproduce:
1. Go to Settings
2. Click on Configure Document Layout
3. In Company Details, select a word
4. (eg: YourCompany)
5. Color half in yellow and half in red
6. (eg: Your in yellow, Company in red)
7. Then select the whole word
8. Color it in a unified color (eg: black)
9. Traceback

Cause of the issue:
range.setEnd(...endPos(last)) was throwing a warning:
During applyColor, Sanitize is called,
which merges similar nodes. (using moveNodes)
After the merge, out of n similar nodes,
only the first one is still contained in the document.

opw-3502124

closes odoo/odoo#144619

X-original-commit: 43a5aec38809f3e7e29b278704fc2143d6cc236e
Signed-off-by: Nicolas Bayet (nby) <nby@odoo.com>
Signed-off-by: Antoine Demany (ande) <ande@odoo.com>
This commit is contained in:
Antoine (ande)
2023-12-01 19:25:35 +00:00
parent b243849b07
commit 364be6ebad
@@ -1974,7 +1974,9 @@ export class Wysiwyg extends Component {
if (color && !isCSSColor(color) && !weUtils.isColorGradient(color)) {
color = (colorType === "text" ? 'text-' : 'bg-') + color;
}
const coloredElements = this.odooEditor.execCommand('applyColor', color, colorType === 'text' ? 'color' : 'backgroundColor', this.lastMediaClicked);
let coloredElements = this.odooEditor.execCommand('applyColor', color, colorType === 'text' ? 'color' : 'backgroundColor', this.lastMediaClicked);
// Some nodes returned by applyColor can be removed of the document by the sanitization in historyStep
coloredElements = coloredElements.filter(element => this.odooEditor.document.contains(element));
const coloredTds = coloredElements && coloredElements.length && Array.isArray(coloredElements) && coloredElements.filter(coloredElement => coloredElement.classList.contains('o_selected_td'));
if (coloredTds.length) {