From 36b5757dcde63781a3bab2cf57779d207943606d Mon Sep 17 00:00:00 2001 From: Deependra Solanki Date: Mon, 17 Apr 2023 05:27:54 +0000 Subject: [PATCH] [FIX] web_editor: fix line merge on color change Before this commit: When using shift+enter to move to a new line, now applying bold, italics, underline, etc and then trying to add a color to both lines would result in lines merging. After this commit: Now when the both lines are bold and then applying a color to both the lines would no longer merge. closes odoo/odoo#119701 Task: 3269922 X-original-commit: 0473dbd0090dd7b2fb1ff59a83a38df941303681 Signed-off-by: David Monjoie (dmo) --- .../editor/odoo-editor/src/commands/commands.js | 2 +- .../editor/odoo-editor/test/spec/color.test.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js index e757deee2ee..533c0a7c4a7 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/commands/commands.js @@ -567,7 +567,7 @@ export const editorCommands = { font = []; } } else if ((node.nodeType === Node.TEXT_NODE && !isWhitespace(node)) - || node.nodeName === "BR" + || (node.nodeName === 'BR' && isEmptyBlock(node.parentNode)) || (node.nodeType === Node.ELEMENT_NODE && ['inline', 'inline-block'].includes(getComputedStyle(node).display) && !isWhitespace(node.textContent) && diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js index aebd678e0af..50153b142c8 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/color.test.js @@ -61,4 +61,20 @@ describe('applyColor', () => { contentAfter: '

[

]

', }); }); + it('should not merge line on background color change', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[abcd
efghi]

', + stepFunction: setColor('rgb(255, 0, 0)', 'backgroundColor'), + contentAfter: '

[abcd
' + + 'efghi]

', + }); + }); + it('should not merge line on color change', async () => { + await testEditor(BasicEditor, { + contentBefore: '

[abcd
efghi]

', + stepFunction: setColor('rgb(255, 0, 0)', 'color'), + contentAfter: '

[abcd
' + + 'efghi]

', + }); + }); });