From e7828c362718b40ed74920a1ce3619766fa84ff2 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Thu, 11 Jul 2019 13:20:28 +0000 Subject: [PATCH] [FIX] web_editor: properly insert character in empty nested list Fix a bug that can be reproduced like so: - Insert list - Type char - ENTER - TAB - Type char The character gets inserted _after_ the `br` instead of replacing it. closes odoo/odoo#34805 Signed-off-by: Pierre Paridans --- .../static/src/js/wysiwyg/plugin/helper.js | 3 ++ .../static/tests/wysiwyg_keyboard_tests.js | 31 +++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js b/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js index a025d6a0082..1738e6e7b48 100644 --- a/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js +++ b/addons/web_editor/static/src/js/wysiwyg/plugin/helper.js @@ -1885,6 +1885,9 @@ var HelperPlugin = AbstractPlugin.extend({ // Create empty text node to have a range into the node if (range.sc.tagName && !dom.isVoid(range.sc) && !range.sc.childNodes[range.so]) { $(range.sc).append(invisible); + if (invisible.previousSibling && invisible.previousSibling.tagName === "BR") { + invisible.previousSibling.remove(); + } range = this.context.invoke('editor.setRange', invisible, 0); } diff --git a/addons/web_editor/static/tests/wysiwyg_keyboard_tests.js b/addons/web_editor/static/tests/wysiwyg_keyboard_tests.js index e59f8d14539..861b574f9c6 100644 --- a/addons/web_editor/static/tests/wysiwyg_keyboard_tests.js +++ b/addons/web_editor/static/tests/wysiwyg_keyboard_tests.js @@ -811,6 +811,18 @@ var keyboardTestsChar = [{ start: "b:contents(0)->1", }, }, + { + name: "'a' in empty li", + content: '', + steps: [{ + start: "p->1", + key: 'a', + }], + test: { + content: '', + start: "p:contents(0)->1", + }, + }, ]; QUnit.test('Char', function (assert) { @@ -2239,6 +2251,25 @@ var keyboardTestsComplex = [{ start: "p:eq(1)->0", }, }, + // List indent + { + name: "ENTER -> TAB -> a' at end of li > p (split -> indent -> write)", + content: '', + steps: [{ + start: "p:contents()[0]->1", + key: 'ENTER', + }, + { + key: 'TAB', + }, + { + key: 'a', + }], + test: { + content: '', + start: "p:eq(1):contents()[0]->1", + }, + }, ]; QUnit.test('Complex', function (assert) {