Added text emoticons to autocomplete (#3312)
Этот коммит содержится в:
коммит произвёл
Joram Wilander
родитель
f6fc4bdbdb
Коммит
163d29f8fa
@@ -43,14 +43,29 @@ class EmoticonSuggestion extends Suggestion {
|
|||||||
|
|
||||||
export default class EmoticonProvider {
|
export default class EmoticonProvider {
|
||||||
handlePretextChanged(suggestionId, pretext) {
|
handlePretextChanged(suggestionId, pretext) {
|
||||||
const captured = (/(?:^|\s)(:([a-zA-Z0-9_+\-]*))$/g).exec(pretext);
|
let hasSuggestions = false;
|
||||||
|
|
||||||
|
// look for partial matches among the named emojis
|
||||||
|
const captured = (/(?:^|\s)(:([^:\s]*))$/g).exec(pretext);
|
||||||
if (captured) {
|
if (captured) {
|
||||||
const text = captured[1];
|
const text = captured[1];
|
||||||
const partialName = captured[2];
|
const partialName = captured[2];
|
||||||
|
|
||||||
const matched = [];
|
const matched = [];
|
||||||
|
|
||||||
for (const [name, emoticon] of Emoticons.getEmoticonsByName()) {
|
const emoticons = Emoticons.getEmoticonsByName();
|
||||||
|
|
||||||
|
// check for text emoticons
|
||||||
|
for (const emoticon of Object.keys(Emoticons.emoticonPatterns)) {
|
||||||
|
if (Emoticons.emoticonPatterns[emoticon].test(text)) {
|
||||||
|
SuggestionStore.addSuggestion(suggestionId, text, emoticons.get(emoticon), EmoticonSuggestion, text);
|
||||||
|
|
||||||
|
hasSuggestions = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checked for named emoji
|
||||||
|
for (const [name, emoticon] of emoticons) {
|
||||||
if (name.indexOf(partialName) !== -1) {
|
if (name.indexOf(partialName) !== -1) {
|
||||||
matched.push(emoticon);
|
matched.push(emoticon);
|
||||||
|
|
||||||
@@ -79,9 +94,13 @@ export default class EmoticonProvider {
|
|||||||
if (terms.length > 0) {
|
if (terms.length > 0) {
|
||||||
SuggestionStore.addSuggestions(suggestionId, terms, matched, EmoticonSuggestion, text);
|
SuggestionStore.addSuggestions(suggestionId, terms, matched, EmoticonSuggestion, text);
|
||||||
|
|
||||||
// force the selection to be cleared since the order of elements may have changed
|
hasSuggestions = true;
|
||||||
SuggestionStore.clearSelection(suggestionId);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (hasSuggestions) {
|
||||||
|
// force the selection to be cleared since the order of elements may have changed
|
||||||
|
SuggestionStore.clearSelection(suggestionId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import Constants from './constants.jsx';
|
import Constants from './constants.jsx';
|
||||||
import emojis from './emoji.json';
|
import emojis from './emoji.json';
|
||||||
|
|
||||||
const emoticonPatterns = {
|
export const emoticonPatterns = {
|
||||||
slightly_smiling_face: /(^|\s)(:-?\))(?=$|\s)/g, // :)
|
slightly_smiling_face: /(^|\s)(:-?\))(?=$|\s)/g, // :)
|
||||||
wink: /(^|\s)(;-?\))(?=$|\s)/g, // ;)
|
wink: /(^|\s)(;-?\))(?=$|\s)/g, // ;)
|
||||||
open_mouth: /(^|\s)(:o)(?=$|\s)/gi, // :o
|
open_mouth: /(^|\s)(:o)(?=$|\s)/gi, // :o
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user