fix EmojiProvider for new QueryMatcher

pull/21833/head
Aviral Dasgupta 2017-02-10 23:35:13 +05:30
parent 0653343319
commit e65744abdc
No known key found for this signature in database
GPG Key ID: 5FD1E9F4FFD3DA80
1 changed files with 9 additions and 3 deletions

View File

@ -7,14 +7,20 @@ import {PillCompletion} from './Components';
import type {SelectionRange, Completion} from './Autocompleter'; import type {SelectionRange, Completion} from './Autocompleter';
const EMOJI_REGEX = /:\w*:?/g; const EMOJI_REGEX = /:\w*:?/g;
const EMOJI_SHORTNAMES = Object.keys(emojioneList); const EMOJI_SHORTNAMES = Object.keys(emojioneList).map(shortname => {
return {
shortname,
};
});
let instance = null; let instance = null;
export default class EmojiProvider extends AutocompleteProvider { export default class EmojiProvider extends AutocompleteProvider {
constructor() { constructor() {
super(EMOJI_REGEX); super(EMOJI_REGEX);
this.matcher = new FuzzyMatcher(EMOJI_SHORTNAMES); this.matcher = new FuzzyMatcher(EMOJI_SHORTNAMES, {
keys: 'shortname',
});
} }
async getCompletions(query: string, selection: SelectionRange) { async getCompletions(query: string, selection: SelectionRange) {
@ -24,7 +30,7 @@ export default class EmojiProvider extends AutocompleteProvider {
let {command, range} = this.getCurrentCommand(query, selection); let {command, range} = this.getCurrentCommand(query, selection);
if (command) { if (command) {
completions = this.matcher.match(command[0]).map(result => { completions = this.matcher.match(command[0]).map(result => {
const shortname = EMOJI_SHORTNAMES[result]; const {shortname} = result;
const unicode = shortnameToUnicode(shortname); const unicode = shortnameToUnicode(shortname);
return { return {
completion: unicode, completion: unicode,