]> cat aescling's git repositories - mastodon.git/commitdiff
fulltext mojo suggestions
authorOndřej Hruška <ondra@ondrovo.com>
Wed, 20 Sep 2017 20:13:09 +0000 (22:13 +0200)
committerOndřej Hruška <ondra@ondrovo.com>
Wed, 20 Sep 2017 20:13:09 +0000 (22:13 +0200)
app/javascript/mastodon/actions/compose.js

index fc154f90ab4b324b1eab83f01f76a928033887c1..c86184046e586b46d9336b8691a468ac13a912ca 100644 (file)
@@ -238,9 +238,17 @@ export function fetchComposeSuggestions(token) {
       // TODO when we have custom emojons merged, add them to this shortcode list
     }
     return (dispatch) => {
-      dispatch(readyComposeSuggestionsTxt(token, allShortcodes.filter((sc) => {
-        return sc.indexOf(token) === 0;
-      })));
+      const innertxt = token.slice(1);
+      if (innertxt.length > 1) { // prevent searching single letter, causes lag
+        dispatch(readyComposeSuggestionsTxt(token, allShortcodes.filter((sc) => {
+          return sc.indexOf(innertxt) !== -1;
+        }).sort((a, b) => {
+          if (a.indexOf(token) === 0 && b.indexOf(token) === 0) return a.localeCompare(b);
+          if (a.indexOf(token) === 0) return -1;
+          if (b.indexOf(token) === 0) return 1;
+          return a.localeCompare(b);
+        })));
+      }
     };
   } else {
     // hashtag
This page took 0.028546 seconds and 3 git commands to generate.