[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) <age@odoo.com>
This commit is contained in:
@@ -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)];
|
||||
|
||||
@@ -126,6 +126,31 @@ QUnit.module(
|
||||
<p placeholder=\"Type "/" for commands\" class=\"oe-hint oe-command-temporary-hint\"><br></p></div></div><p><br></p>`,
|
||||
);
|
||||
});
|
||||
|
||||
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,
|
||||
`<div class="o_editor_banner o_not_editable lh-1 d-flex align-items-center alert alert-info pb-0 pt-3" role="status" data-oe-protected="true" contenteditable="false">
|
||||
<i class="fs-4 fa fa-info-circle mb-3" aria-label="Banner Info"></i>
|
||||
<div class="w-100 ms-3" data-oe-protected="false" contenteditable="true">
|
||||
<p><br></p>
|
||||
</div>
|
||||
</div><p placeholder=\"Type "/" for commands\" class=\"oe-hint oe-command-temporary-hint\"><br></p>`,
|
||||
"should not remove banner when ctrl+a and backspace are performed",
|
||||
);
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user