From f52ade119318096d1920e2fcf54618809617595f Mon Sep 17 00:00:00 2001 From: JC Brand Date: Thu, 5 Sep 2019 16:17:59 +0200 Subject: [PATCH] emoji-views: don't iterate over all emojis if... new search term includes the previous one --- src/converse-emoji-views.js | 12 +++++++++++- src/templates/emojis.html | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/converse-emoji-views.js b/src/converse-emoji-views.js index d3a0f360f..25e300a49 100644 --- a/src/converse-emoji-views.js +++ b/src/converse-emoji-views.js @@ -147,6 +147,7 @@ converse.plugins.add('converse-emoji-views', { }, async initialize () { + this.search_results = []; this.debouncedFilter = debounce(input => this.filter(input.value), 150); this.model.on('change:query', this.render, this); this.model.on('change:current_skintone', this.render, this); @@ -168,7 +169,8 @@ converse.plugins.add('converse-emoji-views', { 'skintones': ['tone1', 'tone2', 'tone3', 'tone4', 'tone5'], 'toned_emojis': _converse.emojis.toned, 'transform': u.getEmojiRenderer(), - 'transformCategory': shortname => u.getEmojiRenderer()(this.getTonedShortname(shortname)) + 'transformCategory': shortname => u.getEmojiRenderer()(this.getTonedShortname(shortname)), + 'search_results': this.search_results } ) ); @@ -180,6 +182,14 @@ converse.plugins.add('converse-emoji-views', { }, filter (value, set_property) { + const old_query = this.model.get('query'); + if (!value) { + this.search_results = []; + } else if (old_query && value.includes(old_query)) { + this.search_results = this.search_results.filter(e => _converse.FILTER_CONTAINS(e.sn, value)); + } else { + this.search_results = _converse.emojis_list.filter(e => _converse.FILTER_CONTAINS(e.sn, value)); + } this.model.set({'query': value}); if (set_property) { // XXX: Ideally we would set `query` on the model and diff --git a/src/templates/emojis.html b/src/templates/emojis.html index 866ed6140..ba99da775 100644 --- a/src/templates/emojis.html +++ b/src/templates/emojis.html @@ -15,7 +15,7 @@ {[ if (o.query) { ]} {{{o.__('Search results')}}}