From a3d20bd96dd82958e1280c6fcbcabfc062c617e4 Mon Sep 17 00:00:00 2001 From: vishal padhiyar Date: Wed, 4 Jan 2023 09:59:42 +0000 Subject: [PATCH] [FIX] web_editor: inconsistent behaviour of the font size selection Before this commit: Selecting some text and changing its size will never allow you to select 13 and selecting default will make the text bigger than the surrounding text. Example in project: the default size is 13px (the editor parses that info and display 13px as the font-size), but if you want to set any text to that value you can't. Users could set any text to that value by selecting "default" font-size instead of 13 After this commit: "default" sets to "font-size: medium", which is often not correct. It should instead, do a "font-size: inherit" so that it's the default for the current context. Hence, removed that medium font-size rule and let the cascade do it. Task-3095887 closes odoo/odoo#109835 X-original-commit: 9878579f62b493958bb6a98e2cdc466bfc2954d8 Signed-off-by: David Monjoie (dmo) --- .../src/js/editor/odoo-editor/src/utils/utils.js | 2 +- .../js/editor/odoo-editor/test/spec/format.test.js | 14 ++++++++++++++ addons/web_editor/static/src/xml/editor.xml | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js index 189c2580473..c0d6b60bfd1 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/utils/utils.js @@ -1048,7 +1048,7 @@ export const formatSelection = (editor, formatName, {applyStyle, formatProps} = tag.remove(); formatSpec.addStyle(getOrCreateSpan(selectedTextNode, inlineAncestors), formatProps); } - } else { + } else if (formatName !== 'fontSize' || formatProps.size !== undefined) { formatSpec.addStyle(getOrCreateSpan(selectedTextNode, inlineAncestors), formatProps); } } diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js index 30646c2c185..aca00d942f0 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/format.test.js @@ -745,6 +745,20 @@ describe('Format', () => { contentAfter: '

b[c]d

', }); }); + it('should change the font-size to default', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[ab]

', + stepFunction: setFontSize(), + contentAfter: '

[ab]

', + }); + }); + it('should change the font-size to default removing the existing style with no empty span at the end', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[abc]

', + stepFunction: setFontSize(), + contentAfter: '

[abc]

', + }); + }); }); it('should add style to a span parent of an inline', async () => { diff --git a/addons/web_editor/static/src/xml/editor.xml b/addons/web_editor/static/src/xml/editor.xml index c877510ccd8..ec60ab859f8 100644 --- a/addons/web_editor/static/src/xml/editor.xml +++ b/addons/web_editor/static/src/xml/editor.xml @@ -84,7 +84,7 @@