Skip to content

A platform for community discussion. Free, open, simple.

DEV: Apply code review.

Bianca Nenciua8e8473ea54c
diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 2d93bb254a8..cddb33cbdfd 100644
--- a/app/assets/javascripts/discourse/components/d-editor.js.es6
+++ b/app/assets/javascripts/discourse/components/d-editor.js.es6
@@ -410,12 +410,17 @@ export default Ember.Component.extend({
},
onKeyUp(text, cp) {
- const regex = self.siteSettings.enable_inline_emoji_translation
- ? /(:(?!:).?[\w-]*:?(?!:)(?:t\d?)?:?) ?$/gi
- : /(?:^|[^a-z])(:(?!:).?[\w-]*:?(?!:)(?:t\d?)?:?) ?$/gi;
+ // Regular expressions used to extract emoji name from text.
+ // The space version requires a ' ' (space) before the emoji name
+ // (i.e. ' :smile'), while the other one does not and is used
+ // when enable_inline_emoji_translation is true.
+ const noSpaceColonEmoji = /(:(?!:).?[\w-]*:?(?!:)(?:t\d?)?:?) ?$/gi;
+ const spaceColonEmoji = /(?:^|[^a-z])(:(?!:).?[\w-]*:?(?!:)(?:t\d?)?:?) ?$/gi;
+ const regex = self.siteSettings.enable_inline_emoji_translation
+ ? noSpaceColonEmoji
+ : spaceColonEmoji;
const matches = regex.exec(text.substring(0, cp));
-
if (matches && matches[1]) {
return [matches[1]];
}
diff --git a/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6 b/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6
index 533dd761394..548cf74638f 100644
--- a/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6
+++ b/app/assets/javascripts/pretty-text/engines/discourse-markdown/emoji.js.es6
@@ -195,7 +195,7 @@ function applyEmoji(
for (i = 0; i < content.length - 1; i++) {
let offset = 0;
- let emojiName = getEmojiName(content, i, state, inlineEmoji);
+ const emojiName = getEmojiName(content, i, state, inlineEmoji);
let token = null;
if (emojiName) {