1
0
mirror of https://github.com/matrix-org/matrix-react-sdk.git synced 2025-11-07 10:46:24 +03:00

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

@@ -9,17 +9,18 @@ let instance = null;
export default class RoomProvider extends AutocompleteProvider {
constructor() {
super();
super(ROOM_REGEX, {
keys: ['displayName', 'userId']
});
this.fuse = new Fuse([], {
keys: ['name', 'roomId', 'aliases']
});
}
getCompletions(query: String) {
getCompletions(query: string, selection: {start: number, end: number}) {
let client = MatrixClientPeg.get();
let completions = [];
const matches = query.match(ROOM_REGEX);
const command = matches && matches[0];
const command = this.getCurrentCommand(query, selection);
if(command) {
// the only reason we need to do this is because Fuse only matches on properties
this.fuse.set(client.getRooms().filter(room => !!room).map(room => {
@@ -29,7 +30,7 @@ export default class RoomProvider extends AutocompleteProvider {
aliases: room.getAliases()
};
}));
completions = this.fuse.search(command).map(room => {
completions = this.fuse.search(command[0]).map(room => {
return {
title: room.name,
subtitle: room.roomId