Yuki Takei 8 år sedan
förälder
incheckning
ebfa0ae2ec
1 ändrade filer med 25 tillägg och 25 borttagningar
  1. 25 25
      resource/js/components/PageEditor/Editor.js

+ 25 - 25
resource/js/components/PageEditor/Editor.js

@@ -86,35 +86,35 @@ export default class Editor extends React.Component {
   autoCompleteEmoji() {
   autoCompleteEmoji() {
     const cm = this.getCodeMirror();
     const cm = this.getCodeMirror();
 
 
+    // see https://regex101.com/r/gy3i03/1
+    const pattern = /:[^:\s]+/
+
+    const currentPos = cm.getCursor();
+    // find previous ':shortname'
+    const sc = cm.getSearchCursor(pattern, currentPos, { multiline: false });
+    if (sc.findPrevious()) {
+      const isInputtingEmoji = (currentPos.line === sc.to().line && currentPos.ch === sc.to().ch);
+      // return if it isn't inputting emoji
+      if (!isInputtingEmoji) {
+        return;
+      }
+    }
+
     // see https://codemirror.net/doc/manual.html#addon_show-hint
     // see https://codemirror.net/doc/manual.html#addon_show-hint
     cm.showHint({
     cm.showHint({
       completeSingle: false,
       completeSingle: false,
       hint: () => {
       hint: () => {
-        // see https://regex101.com/r/gy3i03/1
-        const pattern = /:[^:\s]+/
-
-        const currentPos = cm.getCursor();
-        // find previous ':shortname'
-        const sc = cm.getSearchCursor(pattern, currentPos, { multiline: false });
-        if (sc.findPrevious()) {
-          const isInputtingEmoji = (currentPos.line === sc.to().line && currentPos.ch === sc.to().ch);
-          // return if it isn't inputting emoji
-          if (!isInputtingEmoji) {
-            return;
-          }
-
-          const matched = cm.getDoc().getRange(sc.from(), sc.to());
-          const term = matched.replace(':', '');  // remove ':' in the head
-
-          // get a list of shortnames
-          const shortnames = this.searchEmojiShortnames(term);
-          if (shortnames.length >= 1) {
-            return {
-              list: this.generateEmojiRenderer(shortnames),
-              from: sc.from(),
-              to: sc.to(),
-            };
-          }
+        const matched = cm.getDoc().getRange(sc.from(), sc.to());
+        const term = matched.replace(':', '');  // remove ':' in the head
+
+        // get a list of shortnames
+        const shortnames = this.searchEmojiShortnames(term);
+        if (shortnames.length >= 1) {
+          return {
+            list: this.generateEmojiRenderer(shortnames),
+            from: sc.from(),
+            to: sc.to(),
+          };
         }
         }
       },
       },
     });
     });