about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorOndřej Hruška <ondra@ondrovo.com>2017-09-20 22:13:09 +0200
committerOndřej Hruška <ondra@ondrovo.com>2017-09-20 22:13:09 +0200
commit514edd3c23b9a563aae6a670a7862f6475fd218c (patch)
treee3c102493c6922a6f5eb7a011c0cdbbf3f6da948 /app
parenta3760b7729f9a6ad93591d9c0cdfa39e3b36d483 (diff)
fulltext mojo suggestions
Diffstat (limited to 'app')
-rw-r--r--app/javascript/mastodon/actions/compose.js14
1 files changed, 11 insertions, 3 deletions
diff --git a/app/javascript/mastodon/actions/compose.js b/app/javascript/mastodon/actions/compose.js
index fc154f90a..c86184046 100644
--- a/app/javascript/mastodon/actions/compose.js
+++ b/app/javascript/mastodon/actions/compose.js
@@ -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