[FIX] web_editor: close powerbox when keyup outside its block node

Before this commit:

The Patience diff algorithm uses the text added in the `closestBlock` node to
the node where the powerbox is opened. If the user switched to a different block
using `ArrowLeft` or `ArrowRight` keys, it would result in the algorithm not
searching for the typed text in the other block.

After this commit:

The powerbox will be closed if the keyup event occurs in a different block than
the one in which the powerbox was initially opened.

task-3212128

closes odoo/odoo#141785

X-original-commit: 272614a7b668d361d6ea4177602b249608af34bb
Signed-off-by: Antoine Guenet (age) <age@odoo.com>
This commit is contained in:
Deependra Solanki
2023-11-20 11:13:17 +00:00
parent 1f4bb22d8e
commit 11242d8886
2 changed files with 18 additions and 1 deletions
@@ -333,7 +333,12 @@ export class Powerbox {
true,
);
this._context.lastText = diff.bMove.join('');
if (this._context.lastText.match(/\s/)) {
const selection = this.document.getSelection();
if (
this._context.lastText.match(/\s/) ||
!selection ||
this._context.initialTarget !== closestBlock(selection.anchorNode)
) {
this.close();
} else {
const term = this._context.lastText.toLowerCase()
@@ -66,6 +66,18 @@ describe('Powerbox', () => {
contentAfter: '<h1>ab[]</h1>',
});
});
it('should close the powerbox if keyup event is called on other block', async () => {
await testEditor(BasicEditor, {
contentBefore: '<p>ab</p><p>c[]d</p>',
stepFunction: async (editor) => {
await insertText(editor, '/');
window.chai.expect(editor.powerbox.isOpen).to.be.true;
setSelection(editor.editable.firstChild, 1);
await triggerEvent(editor.editable, 'keyup');
window.chai.expect(editor.powerbox.isOpen).to.be.false;
},
});
});
});
it('should insert a 3x3 table on type `/table` in mobile view', async () => {
if(_isMobile()){