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 ca6eadfd36a..cbe380066d2 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 @@ -1,6 +1,6 @@ /** @odoo-module **/ import { patienceDiff } from './patienceDiff.js'; -import { getRangePosition } from '../utils/utils.js'; +import { closestBlock, getRangePosition } from '../utils/utils.js'; const REGEX_RESERVED_CHARS = /[\\^$.*+?()[\]{}|]/g; /** @@ -114,9 +114,11 @@ export class Powerbox { commands = commands.filter(command => !command.isDisabled || !command.isDisabled()).sort(order); commands = this._groupCommands(commands, categories).flatMap(group => group[1]); + const selection = this.document.getSelection(); + const currentBlock = (selection && closestBlock(selection.anchorNode)) || this.editable; this._context = { commands, categories, filteredCommands: commands, selectedCommand: undefined, - initialTarget: this.editable, initialValue: this.editable.textContent, + initialTarget: currentBlock, initialValue: currentBlock.textContent, lastText: undefined, } this.isOpen = true; 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 e2a9f6f2b2a..3f08a7c1a8b 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 @@ -33,6 +33,26 @@ describe('Powerbox', () => { }, }); }); + it('should not filter the powerbox contents when collaborator type on two different blocks', async () => { + await testEditor(BasicEditor, { + contentBefore: '
ab
c[]d
', + stepFunction: async editor => { + await insertText(editor, '/'); + await insertText(editor, 'heading'); + setSelection(editor.editable.firstChild, 1); + window.chai.expect(editor.powerbox.isOpen).to.be.true; + // Mimick a collaboration scenario where another user types + // random text, using `insert` as it won't trigger keyup. + editor.execCommand('insert', 'random text'); + window.chai.expect(editor.powerbox.isOpen).to.be.true; + setSelection(editor.editable.lastChild, 9); + window.chai.expect(editor.powerbox.isOpen).to.be.true; + await insertText(editor, '1'); + window.chai.expect(editor.powerbox.isOpen).to.be.true; + window.chai.expect(getCurrentCommandNames(editor.powerbox)).to.eql(['Heading 1']); + }, + }); + }); it('should execute command and remove term and hot character on Enter', async () => { await testEditor(BasicEditor, { contentBefore: 'ab[]
',