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()){