[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) <dmo@odoo.com>
This commit is contained in:
Stanislas Gueniffey
2023-04-13 17:57:51 +02:00
parent 31b4fc06c4
commit b49823be4c
@@ -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;
}