Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX: Emoji search/autocomplete should respect selected skin tone #11917

Merged
merged 1 commit into from Feb 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/assets/javascripts/discourse/app/components/d-editor.js
Expand Up @@ -542,7 +542,10 @@ export default Component.extend({
}
}

const options = emojiSearch(term, { maxResults: 5 });
const options = emojiSearch(term, {
maxResults: 5,
diversity: this.emojiStore.diversity,
});

return resolve(options);
})
Expand Down
Expand Up @@ -224,6 +224,7 @@ export default Component.extend({
if (event.target.value) {
results.innerHTML = emojiSearch(event.target.value.toLowerCase(), {
maxResults: 10,
diversity: this.emojiStore.diversity,
})
.map(this._replaceEmoji)
.join("");
Expand Down
13 changes: 13 additions & 0 deletions app/assets/javascripts/discourse/tests/unit/lib/emoji-test.js
Expand Up @@ -136,5 +136,18 @@ discourseModule("Unit | Utility | emoji", function () {

// able to find middle of line search
assert.equal(emojiSearch("check", { maxResults: 3 }).length, 3);

// appends diversity
assert.deepEqual(emojiSearch("woman_artist", { diversity: 5 }), [
"woman_artist:t5",
]);
assert.deepEqual(emojiSearch("woman_artist", { diversity: 2 }), [
"woman_artist:t2",
]);

// no diversity appended for emojis that can't be diversified
assert.deepEqual(emojiSearch("green_apple", { diversity: 3 }), [
"green_apple",
]);
});
});
7 changes: 6 additions & 1 deletion app/assets/javascripts/pretty-text/addon/emoji.js
Expand Up @@ -210,6 +210,7 @@ export function emojiExists(code) {
let toSearch;
export function emojiSearch(term, options) {
const maxResults = (options && options["maxResults"]) || -1;
const diversity = options && options.diversity;
if (maxResults === 0) {
return [];
}
Expand All @@ -227,7 +228,11 @@ export function emojiSearch(term, options) {
function addResult(t) {
const val = aliasHash[t] || t;
if (results.indexOf(val) === -1) {
results.push(val);
if (diversity && diversity > 1 && isSkinTonableEmoji(val)) {
results.push(`${val}:t${diversity}`);
} else {
results.push(val);
}
}
}

Expand Down