mirror of
https://github.com/element-hq/element-web
synced 2024-11-28 12:28:50 +03:00
Merge branch 't3chguy/improve_command_provider' into develop
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> # Conflicts: # src/autocomplete/CommandProvider.js
This commit is contained in:
commit
e79738de8a
1 changed files with 20 additions and 2 deletions
|
@ -41,8 +41,26 @@ export default class CommandProvider extends AutocompleteProvider {
|
||||||
const {command, range} = this.getCurrentCommand(query, selection);
|
const {command, range} = this.getCurrentCommand(query, selection);
|
||||||
if (!command) return [];
|
if (!command) return [];
|
||||||
|
|
||||||
// if the query is just `/` (and the user hit TAB or waits), show them all COMMANDS otherwise FuzzyMatch them
|
let matches;
|
||||||
const matches = query === '/' ? COMMANDS : this.matcher.match(command[1]);
|
if (command[0] !== command[1]) {
|
||||||
|
// The input looks like a command with arguments, perform exact match
|
||||||
|
const match = COMMANDS.find((o) => o.command === command[1]);
|
||||||
|
if (match) {
|
||||||
|
matches = [match];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't yet have matches
|
||||||
|
if (!matches) {
|
||||||
|
if (query === '/') {
|
||||||
|
// If they have just entered `/` show everything
|
||||||
|
matches = COMMANDS;
|
||||||
|
} else {
|
||||||
|
// otherwise fuzzy match against all of the fields
|
||||||
|
matches = this.matcher.match(command[1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return matches.map((result) => ({
|
return matches.map((result) => ({
|
||||||
// If the command is the same as the one they entered, we don't want to discard their arguments
|
// If the command is the same as the one they entered, we don't want to discard their arguments
|
||||||
completion: result.command === command[1] ? command[0] : (result.command + ' '),
|
completion: result.command === command[1] ? command[0] : (result.command + ' '),
|
||||||
|
|
Loading…
Reference in a new issue