Commit 9e1cf71b authored by Harrison Healey's avatar Harrison Healey Committed by Joram Wilander
Browse files

Fixed emoticons consuming the preceeding whitespace (#3187)

parent 8e2f427b
......@@ -132,7 +132,7 @@ export function getEmoticonsByCodePoint() {
export function handleEmoticons(text, tokens) {
let output = text;
function replaceEmoticonWithToken(fullMatch, matchText, name) {
function replaceEmoticonWithToken(fullMatch, prefix, matchText, name) {
if (getEmoticonsByName().has(name)) {
const index = tokens.size;
const alias = `MM_EMOTICON${index}`;
......@@ -143,14 +143,14 @@ export function handleEmoticons(text, tokens) {
originalText: fullMatch
});
return alias;
return prefix + alias;
}
return fullMatch;
}
// match named emoticons like :goat:
output = output.replace(/(:([a-zA-Z0-9_-]+):)/g, (fullMatch, matchText, name) => replaceEmoticonWithToken(fullMatch, matchText, name));
output = output.replace(/(:([a-zA-Z0-9_-]+):)/g, (fullMatch, matchText, name) => replaceEmoticonWithToken(fullMatch, '', matchText, name));
// match text smilies like :D
for (const name of Object.keys(emoticonPatterns)) {
......@@ -158,7 +158,7 @@ export function handleEmoticons(text, tokens) {
// this might look a bit funny, but since the name isn't contained in the actual match
// like with the named emoticons, we need to add it in manually
output = output.replace(pattern, (fullMatch, matchText) => replaceEmoticonWithToken(fullMatch, matchText, name));
output = output.replace(pattern, (fullMatch, prefix, matchText) => replaceEmoticonWithToken(fullMatch, prefix, matchText, name));
}
return output;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment