From 508d4d75a1de599812cd21eac49d12e13860c441 Mon Sep 17 00:00:00 2001 From: dhba-odoo Date: Fri, 3 Mar 2023 07:26:43 +0000 Subject: [PATCH] [FIX] web_editor: shift+enter on styled elements. Before this commit: After selecting the text of shift+enter which is styled and pressing any key the new hideous child gets born. After this commit: Now, The new input will replace the selected text. Task-3209969 closes odoo/odoo#119506 X-original-commit: f15d5ad27c6b764f54904f6ea8f6a714974b7bd0 Signed-off-by: David Monjoie (dmo) --- .../js/editor/odoo-editor/src/utils/utils.js | 7 +----- .../odoo-editor/test/spec/format.test.js | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 7 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 6fabbba3fcb..612b249f67c 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 @@ -1897,12 +1897,7 @@ export function fillEmpty(el) { blockEl.appendChild(br); fillers.br = br; } - if ( - !el.textContent.length && - !isBlock(el) && - el.nodeName !== 'BR' && - !el.hasAttribute("data-oe-zws-empty-inline") - ) { + if (!isVisible(el) && !el.hasAttribute("data-oe-zws-empty-inline")) { // As soon as there is actual content in the node, the zero-width space // is removed by the sanitize function. const zws = document.createTextNode('\u200B'); 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 f086d40c1ba..b593eb07a15 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 @@ -1,7 +1,7 @@ /** @odoo-module */ import { isSelectionFormat } from '../../src/utils/utils.js'; -import { BasicEditor, testEditor, setTestSelection, Direction, unformat } from '../utils.js'; +import { BasicEditor, testEditor, setTestSelection, Direction, unformat, insertText } from '../utils.js'; const bold = async editor => { await editor.execCommand('bold'); @@ -520,6 +520,27 @@ describe('Format', () => { contentAfter: `

a[b]c

`, }); }); + it('should insert new character inside strikethrough at first position', async () => { + await testEditor(BasicEditor, { + contentBefore: `

d[a${s('bc]

')}

`, + stepFunction: async editor => { + insertText(editor, 'A'); + }, + contentAfter: `

dA[]${s(`

`)}

`, + }); + await testEditor(BasicEditor, { + contentBefore: `

[a${s('bc]

')}

`, + stepFunction: async editor => { + insertText(editor, 'A'); + }, + contentAfter: `

A[]${s(`

`)}

`, + // Note: In the browser, the actual result is the following: + // contentAfter: `

${s(`A[]

`)}

`, + // It is arguable which version is better than the other but in + // any case this is a trade-off because it matches the native + // behavior of contentEditable in that case. + }); + }); }); describe('underline + strikeThrough', () => {