Hide/show autocomplete based on selection state

This commit is contained in:
Aviral Dasgupta 2016-06-21 15:46:20 +05:30
parent f6a76edfdf
commit fb6eec0f7d
11 changed files with 114 additions and 43 deletions

View file

@ -2,26 +2,27 @@ import AutocompleteProvider from './AutocompleteProvider';
import Q from 'q';
import Fuse from 'fuse.js';
const ROOM_REGEX = /@[^\s]*/g;
const USER_REGEX = /@[^\s]*/g;
let instance = null;
export default class UserProvider extends AutocompleteProvider {
constructor() {
super();
super(USER_REGEX, {
keys: ['displayName', 'userId']
});
this.users = [];
this.fuse = new Fuse([], {
keys: ['displayName', 'userId']
})
}
getCompletions(query: String) {
getCompletions(query: string, selection: {start: number, end: number}) {
let completions = [];
let matches = query.match(ROOM_REGEX);
let command = matches && matches[0];
let command = this.getCurrentCommand(query, selection);
if(command) {
this.fuse.set(this.users);
completions = this.fuse.search(command).map(user => {
completions = this.fuse.search(command[0]).map(user => {
return {
title: user.displayName || user.userId,
description: user.userId