feat: implement autocomplete replacement
This commit is contained in:
parent
8961c87cf9
commit
cccc58b47f
13 changed files with 271 additions and 121 deletions
|
@ -1,42 +1,45 @@
|
|||
import React from 'react';
|
||||
import AutocompleteProvider from './AutocompleteProvider';
|
||||
import Q from 'q';
|
||||
import Fuse from 'fuse.js';
|
||||
import {TextualCompletion} from './Components';
|
||||
|
||||
const COMMANDS = [
|
||||
{
|
||||
command: '/me',
|
||||
args: '<message>',
|
||||
description: 'Displays action'
|
||||
description: 'Displays action',
|
||||
},
|
||||
{
|
||||
command: '/ban',
|
||||
args: '<user-id> [reason]',
|
||||
description: 'Bans user with given id'
|
||||
description: 'Bans user with given id',
|
||||
},
|
||||
{
|
||||
command: '/deop'
|
||||
command: '/deop',
|
||||
args: '<user-id>',
|
||||
description: 'Deops user with given id',
|
||||
},
|
||||
{
|
||||
command: '/encrypt'
|
||||
},
|
||||
{
|
||||
command: '/invite'
|
||||
command: '/invite',
|
||||
args: '<user-id>',
|
||||
description: 'Invites user with given id to current room'
|
||||
},
|
||||
{
|
||||
command: '/join',
|
||||
args: '<room-alias>',
|
||||
description: 'Joins room with given alias'
|
||||
description: 'Joins room with given alias',
|
||||
},
|
||||
{
|
||||
command: '/kick',
|
||||
args: '<user-id> [reason]',
|
||||
description: 'Kicks user with given id'
|
||||
description: 'Kicks user with given id',
|
||||
},
|
||||
{
|
||||
command: '/nick',
|
||||
args: '<display-name>',
|
||||
description: 'Changes your display nickname'
|
||||
}
|
||||
description: 'Changes your display nickname',
|
||||
},
|
||||
];
|
||||
|
||||
let COMMAND_RE = /(^\/\w*)/g;
|
||||
|
@ -47,19 +50,23 @@ export default class CommandProvider extends AutocompleteProvider {
|
|||
constructor() {
|
||||
super(COMMAND_RE);
|
||||
this.fuse = new Fuse(COMMANDS, {
|
||||
keys: ['command', 'args', 'description']
|
||||
keys: ['command', 'args', 'description'],
|
||||
});
|
||||
}
|
||||
|
||||
getCompletions(query: string, selection: {start: number, end: number}) {
|
||||
let completions = [];
|
||||
const command = this.getCurrentCommand(query, selection);
|
||||
if(command) {
|
||||
let {command, range} = this.getCurrentCommand(query, selection);
|
||||
if (command) {
|
||||
completions = this.fuse.search(command[0]).map(result => {
|
||||
return {
|
||||
title: result.command,
|
||||
subtitle: result.args,
|
||||
description: result.description
|
||||
completion: result.command + ' ',
|
||||
component: (<TextualCompletion
|
||||
title={result.command}
|
||||
subtitle={result.args}
|
||||
description={result.description}
|
||||
/>),
|
||||
range,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -71,7 +78,7 @@ export default class CommandProvider extends AutocompleteProvider {
|
|||
}
|
||||
|
||||
static getInstance(): CommandProvider {
|
||||
if(instance == null)
|
||||
if (instance == null)
|
||||
instance = new CommandProvider();
|
||||
|
||||
return instance;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue