DEV: Apply code review.

DEV: Apply code review.
From a8e8473ea54cda1d9fef6fc88720850922c6a0e8 Mon Sep 17 00:00:00 2001
From: Bianca Nenciu <nenciu.bianca@gmail.com>
Date: Tue, 4 Dec 2018 14:07:13 +0200
Subject: [PATCH] DEV: Apply code review.


diff --git a/app/assets/javascripts/discourse/components/d-editor.js.es6 b/app/assets/javascripts/discourse/components/d-editor.js.es6
index 2d93bb2..cddb33c 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 533dd76..548cf74 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) {

GitHub

1 Like