1
0
mirror of https://github.com/discourse/discourse.git synced 2025-03-09 14:34:35 +00:00

FIX: Search aliases but don't add them to the results

This commit is contained in:
Robin Ward 2016-03-04 16:08:17 -05:00
parent 396713718b
commit 0a96829508

@ -48,9 +48,11 @@ var emojiHash = {};
// add all default emojis // add all default emojis
emoji.forEach(function(code){ emojiHash[code] = true; }); emoji.forEach(function(code){ emojiHash[code] = true; });
// and their aliases // and their aliases
var aliasHash = {};
for (var name in aliases) { for (var name in aliases) {
aliases[name].forEach(function(alias) { aliases[name].forEach(function(alias) {
emojiHash[alias] = true; aliasHash[alias] = name;
}); });
} }
@ -221,27 +223,29 @@ Discourse.Emoji.search = function(term, options) {
var maxResults = (options && options["maxResults"]) || -1; var maxResults = (options && options["maxResults"]) || -1;
if (maxResults === 0) { return []; } if (maxResults === 0) { return []; }
toSearch = toSearch || _.union(_.keys(emojiHash), _.keys(extendedEmoji)).sort(); toSearch = toSearch || _.union(_.keys(emojiHash), _.keys(extendedEmoji), _.keys(aliasHash)).sort();
var i, results = []; var i, results = [];
function addResult(term) {
var done = function() { var val = aliasHash[term] || term;
if (results.indexOf(val) === -1) {
results.push(val);
}
return maxResults > 0 && results.length >= maxResults; return maxResults > 0 && results.length >= maxResults;
} }
for (i=0; i < toSearch.length; i++) { var item;
if (toSearch[i].indexOf(term) === 0) { for (i=0; i<toSearch.length; i++) {
results.push(toSearch[i]); item = toSearch[i];
if(done()) { break; } if (item.indexOf(term) === 0 && addResult(item)) {
return results;
} }
} }
if(!done()){ for (i=0; i<toSearch.length; i++) {
for (i=0; i < toSearch.length; i++) { item = toSearch[i];
if (toSearch[i].indexOf(term) > 0) { if (item.indexOf(term) === 0 && addResult(item)) {
results.push(toSearch[i]); return results;
if(done()) { break; }
}
} }
} }