Merge branch 'develop' into sort-imports
Signed-off-by: Aaron Raimist <aaron@raim.ist>
This commit is contained in:
commit
7b94e13a84
642 changed files with 30052 additions and 8035 deletions
|
@ -25,17 +25,20 @@ import QueryMatcher from './QueryMatcher';
|
|||
import { TextualCompletion } from './Components';
|
||||
import { ICompletion, ISelectionRange } from "./Autocompleter";
|
||||
import { Command, Commands, CommandMap } from '../SlashCommands';
|
||||
import { Room } from 'matrix-js-sdk/src/models/room';
|
||||
import { TimelineRenderingType } from '../contexts/RoomContext';
|
||||
|
||||
const COMMAND_RE = /(^\/\w*)(?: .*)?/g;
|
||||
|
||||
export default class CommandProvider extends AutocompleteProvider {
|
||||
matcher: QueryMatcher<Command>;
|
||||
|
||||
constructor() {
|
||||
super(COMMAND_RE);
|
||||
constructor(room: Room, renderingType?: TimelineRenderingType) {
|
||||
super({ commandRegex: COMMAND_RE, renderingType });
|
||||
this.matcher = new QueryMatcher(Commands, {
|
||||
keys: ['command', 'args', 'description'],
|
||||
funcs: [({ aliases }) => aliases.join(" ")], // aliases
|
||||
context: renderingType,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -48,7 +51,7 @@ export default class CommandProvider extends AutocompleteProvider {
|
|||
const { command, range } = this.getCurrentCommand(query, selection);
|
||||
if (!command) return [];
|
||||
|
||||
let matches = [];
|
||||
let matches: Command[] = [];
|
||||
// check if the full match differs from the first word (i.e. returns false if the command has args)
|
||||
if (command[0] !== command[1]) {
|
||||
// The input looks like a command with arguments, perform exact match
|
||||
|
@ -69,7 +72,10 @@ export default class CommandProvider extends AutocompleteProvider {
|
|||
}
|
||||
}
|
||||
|
||||
return matches.filter(cmd => cmd.isEnabled()).map((result) => {
|
||||
return matches.filter(cmd => {
|
||||
const display = !cmd.renderingTypes || cmd.renderingTypes.includes(this.renderingType);
|
||||
return cmd.isEnabled() && display;
|
||||
}).map((result) => {
|
||||
let completion = result.getCommand() + ' ';
|
||||
const usedAlias = result.aliases.find(alias => `/${alias}` === command[1]);
|
||||
// If the command (or an alias) is the same as the one they entered, we don't want to discard their arguments
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue