From b49823be4cd1ddaef7e43fa3778a82d95f15bfca Mon Sep 17 00:00:00 2001 From: Stanislas Gueniffey Date: Mon, 27 Feb 2023 13:22:42 +0000 Subject: [PATCH] [IMP] web_editor: powerbox search from description This commit changes web_editor's powerbox search feature to also look for matches in a command's `description`, in addition to its `groupName` and `title`. For example, typing /track will suggest the Checklist command among the suggestions as its description is "Track tasks with a checklist". Note that only exact matches are considered for the description, while fuzzy matches (with missing chars) work for other attributes. Also fixes a typo in a local variable name because it was hazardous to some people's eyesight. task-3188758 closes odoo/odoo#118486 X-original-commit: 7fa6d48f1b69e4d4806db29310223d326b0e0ed5 Signed-off-by: David Monjoie (dmo) --- .../editor/odoo-editor/src/powerbox/Powerbox.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) 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 bdeb80a8e8e..d50c4197303 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 @@ -334,12 +334,18 @@ export class Powerbox { if (this._context.lastText.match(/\s/)) { this.close(); } else { - const term = this._context.lastText.toLowerCase().replaceAll(/\s/g, '\\s').replaceAll('\u200B', ''); + const term = this._context.lastText.toLowerCase() + .replaceAll(/\s/g, '\\s') + .replaceAll('\u200B', '') + .replace(REGEX_RESERVED_CHARS, '\\$&'); if (term.length) { - const regex = new RegExp(term.split('').map(char => char.replace(REGEX_RESERVED_CHARS, '\\$&')).join('.*'), 'i'); - this._context.filteredCommands = this._context.commands.filter(command => ( - `${command.category} ${command.name}`.toLowerCase().match(regex) - )); + const exactRegex = new RegExp(term, 'i'); + const fuzzyRegex = new RegExp(term.split('').join('.*'), 'i'); + this._context.filteredCommands = this._context.commands.filter(command => { + const commandText = (command.category + ' ' + command.name); + const commandDescription = command.description.replace(/\s/g, ''); + return commandText.match(fuzzyRegex) || commandDescription.match(exactRegex); + }); } else { this._context.filteredCommands = this._context.commands; }