Add fuzzy searching for autocompleting colors

This commit is contained in:
Yash Srivastav 2017-08-10 10:02:43 +05:30
parent 1c8aa7a88f
commit fa021da7cf
No known key found for this signature in database
GPG Key ID: 67A09FFAC003E189

View File

@ -120,8 +120,18 @@ $(function() {
match: /\x03(\d{0,2}|[A-Za-z ]{0,10})$/,
search(term, callback) {
term = term.toLowerCase();
const matchingColorCodes = constants.colorCodeMap
.filter((i) => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term));
.filter((i) => fuzzy.test(term, i[0]) || fuzzy.test(term, i[1]))
.map((i) => {
if (fuzzy.test(term, i[1])) {
return [i[0], fuzzy.match(term, i[1], {
pre: "<b>",
post: "</b>"
}).rendered];
}
return i;
});
callback(matchingColorCodes);
},
@ -140,7 +150,16 @@ $(function() {
search(term, callback, match) {
term = term.toLowerCase();
const matchingColorCodes = constants.colorCodeMap
.filter((i) => i[0].startsWith(term) || i[1].toLowerCase().startsWith(term))
.filter((i) => fuzzy.test(term, i[0]) || fuzzy.test(term, i[1]))
.map((pair) => {
if (fuzzy.test(term, pair[1])) {
return [pair[0], fuzzy.match(term, pair[1], {
pre: "<b>",
post: "</b>"
}).rendered];
}
return pair;
})
.map((pair) => pair.concat(match[1])); // Needed to pass fg color to `template`...
callback(matchingColorCodes);