You've already forked matrix-react-sdk
mirror of
https://github.com/matrix-org/matrix-react-sdk.git
synced 2025-07-18 09:22:18 +03:00
Hide/show autocomplete based on selection state
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user