From 5e76d6d86530808ba55aa6ea084f227ca55cb52f Mon Sep 17 00:00:00 2001 From: unknown Date: Tue, 10 Aug 2021 14:12:00 +0530 Subject: [PATCH] improved emoji suggestions --- src/app/organisms/channel/ChannelViewCmdBar.jsx | 17 ++++++++++++++++- src/app/organisms/channel/ChannelViewInput.jsx | 10 ++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/app/organisms/channel/ChannelViewCmdBar.jsx b/src/app/organisms/channel/ChannelViewCmdBar.jsx index 8dbf8024..f7eaa646 100644 --- a/src/app/organisms/channel/ChannelViewCmdBar.jsx +++ b/src/app/organisms/channel/ChannelViewCmdBar.jsx @@ -276,7 +276,22 @@ function getCmdSuggestions({ prefix, slug }, fireCmd, viewEvent) { } function getEmojiSuggestion(emPrefix, shortcutSlug) { - const result = searchEmoji(shortcutSlug); + let searchTerm = shortcutSlug; + if (searchTerm.length <= 3) { + if (searchTerm.match(/^[-]?(\))/)) searchTerm = 'smile'; + else if (searchTerm.match(/^[-]?(s|S)/)) searchTerm = 'confused'; + else if (searchTerm.match(/^[-]?(o|O|0)/)) searchTerm = 'astonished'; + else if (searchTerm.match(/^[-]?(\|)/)) searchTerm = 'neutral_face'; + else if (searchTerm.match(/^[-]?(d|D)/)) searchTerm = 'grin'; + else if (searchTerm.match(/^[-]?(\/)/)) searchTerm = 'frown'; + else if (searchTerm.match(/^[-]?(p|P)/)) searchTerm = 'stick_out_tongue'; + else if (searchTerm.match(/^'[-]?(\()/)) searchTerm = 'cry'; + else if (searchTerm.match(/^[-]?(x|X)/)) searchTerm = 'dizzy_face'; + else if (searchTerm.match(/^[-]?(\()/)) searchTerm = 'pleading_face'; + else if (searchTerm.match(/^[-]?(\$)/)) searchTerm = 'money'; + else if (searchTerm.match(/^(<3)/)) searchTerm = 'heart'; + } + const result = searchEmoji(searchTerm); if (result.length === 0) viewEvent.emit('cmd_error'); perfectMatchCmd = { prefix: emPrefix, diff --git a/src/app/organisms/channel/ChannelViewInput.jsx b/src/app/organisms/channel/ChannelViewInput.jsx index 0a40117e..e3c90da1 100644 --- a/src/app/organisms/channel/ChannelViewInput.jsx +++ b/src/app/organisms/channel/ChannelViewInput.jsx @@ -213,6 +213,16 @@ function ChannelViewInput({ const cmdPrefix = cmdParts[1]; const cmdSlug = cmdParts[2]; + if (cmdPrefix === ':') { + // skip emoji autofill command if link is suspected. + const checkForLink = targetInput.slice(0, cmdParts.index); + if (checkForLink.match(/(http|https|mailto|matrix|ircs|irc)$/)) { + deactivateCmd(); + viewEvent.emit('cmd_deactivate'); + return; + } + } + cmdCursorPos = cursor; if (cmdSlug === '') { activateCmd(cmdPrefix);