From 11242d8886bd713dc6baf4e099f44a804ae880af Mon Sep 17 00:00:00 2001 From: Deependra Solanki Date: Tue, 7 Nov 2023 12:08:42 +0530 Subject: [PATCH] [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) --- .../js/editor/odoo-editor/src/powerbox/Powerbox.js | 7 ++++++- .../js/editor/odoo-editor/test/spec/powerbox.test.js | 12 ++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/src/powerbox/Powerbox.js b/addons/web_editor/static/src/js/editor/odoo-editor/src/powerbox/Powerbox.js index cbe380066d2..a19c2dc0265 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/src/powerbox/Powerbox.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/src/powerbox/Powerbox.js @@ -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() diff --git a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/powerbox.test.js b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/powerbox.test.js index 3f08a7c1a8b..4bfad7028ad 100644 --- a/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/powerbox.test.js +++ b/addons/web_editor/static/src/js/editor/odoo-editor/test/spec/powerbox.test.js @@ -66,6 +66,18 @@ describe('Powerbox', () => { contentAfter: '

ab[]

', }); }); + it('should close the powerbox if keyup event is called on other block', async () => { + await testEditor(BasicEditor, { + contentBefore: '

ab

c[]d

', + 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()){