Skip to content

Commit

Permalink
Merge pull request #413 from averissimo/fix-emoji-undefined
Browse files Browse the repository at this point in the history
Issue #412 -- fixes three bugs with emojis
  • Loading branch information
davibe committed Nov 29, 2016
2 parents 10c7a89 + 082e72f commit dcc4df5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 5 additions & 3 deletions src/ui/util.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ convertEmoji = (text) ->
unicodeMap = require './emojishortcode'

patterns = [
"(^|[ ])(:[a-zA-Z0-9_\+-]+:)([ ]$)",
"(^|[ ])(:[a-zA-Z0-9_\+-]+:)([ ]|$)",
"(^|[ ])(:\\(:\\)|:\\(\\|\\)|:X\\)|:3|\\(=\\^\\.\\.\\^=\\)|\\(=\\^\\.\\^=\\)|=\\^_\\^=|x_x|X-O|X-o|X\\(|X-\\(|O\\.O|:O|:-O|=O|o\\.o|:o|:-o|=o|D:|>_<|T_T|:'\\(|;_;|='\\(|>\\.<|>:\\(|>:-\\(|>=\\(|:\\(|:-\\(|=\\(|;P|;-P|;p|;-p|:P|:-P|=P|:p|:-p|=p|;\\*|;-\\*|:\\*|:-\\*|:S|:-S|:s|:-s|=\\/|=\\\\|:-\\/|:-\\\\|:\\/|:\\\\|u_u|o_o;|-_-|=\\||:\\||:-\\||B-\\)|B\\)|;-\\)|;\\)|}=\\)|}:-\\)|}:\\)|O=\\)|O:-\\)|O:\\)|\\^_\\^;;|=D|\\^_\\^|:-D|:D|~@~|<3|<\\/3|<\\\\3|\\(]:{|-<@%|:\\)|:-\\)|=\\))([ ]|$)"

]

emojiCodeRegex = new RegExp(patterns.join('|'),'g')
Expand All @@ -93,7 +92,10 @@ convertEmoji = (text) ->
suffix = emoji.slice(emoji.trimRight().length)
prefix = emoji.slice(0, emoji.length - emoji.trimLeft().length)
unicode = unicodeMap[emoji.trim()]
return prefix + unicode + suffix if !!unicode
if unicode?
prefix + unicode + suffix
else
emoji
)
return text
module.exports = {nameof, initialsof, nameofconv, linkto, later, throttle, uniqfn,
Expand Down
13 changes: 7 additions & 6 deletions src/ui/views/input.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,16 @@ module.exports = view (models) ->
#check for emojis after pressing space
if e.keyCode == 32
element = document.getElementById "message-input"
# get cursor position
startSel = element.selectionStart
endSel = element.selectionEnd
# Converts emojicodes (e.g. :smile:, :-) ) to unicode
if models.viewstate.convertEmoji
# get cursor position
startSel = element.selectionStart
len = element.value.length
element.value = convertEmoji(element.value)
# Set cursor position (otherwise it would go to end of inpu)
element.selectionStart = startSel
element.selectionEnd = endSel
# Set cursor position (otherwise it would go to end of inpu)
lenAfter = element.value.length
element.selectionStart = startSel - (len - lenAfter)
element.selectionEnd = element.selectionStart
, onpaste: (e) ->
setTimeout () ->
if not clipboard.readImage().isEmpty() and not clipboard.readText()
Expand Down

0 comments on commit dcc4df5

Please sign in to comment.