From 5f2c143623721564d0489a5ae65d82f74f2a8563 Mon Sep 17 00:00:00 2001 From: "Hubert Van de Walle (huvw)" Date: Tue, 2 Nov 2021 12:33:13 +0000 Subject: [PATCH] [FIX] web_editor: don't show the active style entry if absent Steps to follow - Edit a report with studio - Add an inline text element - Select it - Select the text in the sidebar -> An error is raised Cause of the issue firstButtonEl is undefined because the style section is not always present in the toolbar opw-2674302 closes odoo/odoo#79335 X-original-commit: 45b590d8961d56f8d207c22efbf1ba7188a3b1fa Signed-off-by: David Monjoie (dmo) Signed-off-by: Hubert Van De Walle --- .../static/lib/odoo-editor/src/OdooEditor.js | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js index dc4f26821eb..4dff1d95348 100644 --- a/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js +++ b/addons/web_editor/static/lib/odoo-editor/src/OdooEditor.js @@ -1886,14 +1886,18 @@ export class OdooEditor extends EventTarget { listDropdownButton.closest('button').classList.toggle('active', block.tagName === 'LI'); } } - if (!activeLabel) { - // If no element from the text style dropdown was marked as active, - // mark the paragraph one as active and use its label. - const firstButtonEl = this.toolbar.querySelector('#paragraph'); - firstButtonEl.classList.add('active'); - activeLabel = firstButtonEl.textContent; + + const styleSection = this.toolbar.querySelector('#style'); + if (styleSection) { + if (!activeLabel) { + // If no element from the text style dropdown was marked as active, + // mark the paragraph one as active and use its label. + const firstButtonEl = styleSection.querySelector('#paragraph'); + firstButtonEl.classList.add('active'); + activeLabel = firstButtonEl.textContent; + } + styleSection.querySelector('button span').textContent = activeLabel; } - this.toolbar.querySelector('#style button span').textContent = activeLabel; const linkNode = getInSelection(this.document, 'a'); const linkButton = this.toolbar.querySelector('#createLink');