From 4739433d09856787aed5fad944d2bef823b4cdfc Mon Sep 17 00:00:00 2001 From: dhba Date: Fri, 29 Dec 2023 16:40:13 +0530 Subject: [PATCH] [FIX] web_editor: issue with ctrl+a when banner is first element Before this commit: - When a banner was inserted at the first line and Ctrl+A and backspace is performed, nothing happens. After this commit: - Now, all the content except banner will be selected and removed. task-3432167 closes odoo/odoo#151735 X-original-commit: 530f102720458e5e1c224bf38073cd763309bf0a Signed-off-by: Antoine Guenet (age) --- .../js/editor/odoo-editor/src/utils/utils.js | 2 +- .../web_editor/static/tests/banner_tests.js | 27 ++++++++++++++++++- 2 files changed, 27 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 64af7c5f6e0..1a0fb45673d 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 @@ -858,7 +858,7 @@ export function getDeepestPosition(node, offset) { let direction = DIRECTIONS.RIGHT; let next = node; while (next) { - if (isVisible(next) || isZWS(next)) { + if ((isVisible(next) || isZWS(next)) && (!isBlock(next) || next.isContentEditable)) { // Valid node: update position then try to go deeper. if (next !== node) { [node, offset] = [next, direction ? 0 : nodeSize(next)]; diff --git a/addons/web_editor/static/tests/banner_tests.js b/addons/web_editor/static/tests/banner_tests.js index d1e1bb21c8c..ec90bef2252 100644 --- a/addons/web_editor/static/tests/banner_tests.js +++ b/addons/web_editor/static/tests/banner_tests.js @@ -126,6 +126,31 @@ QUnit.module(



`, ); }); - + QUnit.test("First element of o_editable is not editable", async function (assert) { + const { editor, editable } = onMount(); + const node = editable.querySelector("p"); + setSelection(node, 0); + insertText(editor, '/banner'); + triggerEvent(editor.editable, "keydown", { key: "Enter" }); + await nextTick(); + const p = editable.querySelectorAll('p')[1]; + setSelection(p, 0); + insertText(editor, 'Test1'); + triggerEvent(editor.editable, "input", { inputType: "insertParagraph" }); + insertText(editor, 'Test2'); + triggerEvent(editor.editable, "keydown", { key: "a", ctrlKey: true }); + await nextTick(); + triggerEvent(editor.editable, "input", { inputType: "deleteContentBackward" }); + assert.strictEqual( + editable.innerHTML, + `
+ +
+


+
+


`, + "should not remove banner when ctrl+a and backspace are performed", + ); + }); } );