Skip to content

Commit

Permalink
Message box changes direction explicitly upon input change (#3730)
Browse files Browse the repository at this point in the history
  • Loading branch information
pitamar authored and rodrigok committed Aug 3, 2016
1 parent c7f3b95 commit eff538b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/rocketchat-ui-message/message/messageBox.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,13 @@ Template.messageBox.events
'keydown .input-message': (event) ->
chatMessages[@_id].keydown(@_id, event, Template.instance())

'input .input-message': (event) ->
chatMessages[@_id].valueChanged(@_id, event, Template.instance())

'propertychange .input-message': (event) ->
if event.originalEvent.propertyName is 'value'
chatMessages[@_id].valueChanged(@_id, event, Template.instance())

"click .editing-commands-cancel > button": (e) ->
chatMessages[@_id].clearEditing()

Expand Down
14 changes: 14 additions & 0 deletions packages/rocketchat-ui/lib/chatMessages.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,20 @@ class @ChatMessages
else if k is 75 and ((navigator?.platform?.indexOf('Mac') isnt -1 and event.metaKey and event.shiftKey) or (navigator?.platform?.indexOf('Mac') is -1 and event.ctrlKey and event.shiftKey))
RoomHistoryManager.clear rid

valueChanged: (rid, event) ->
this.determineInputDirection()

determineInputDirection: () ->
this.input.dir = if this.isMessageRtl(this.input.value) then 'rtl' else 'ltr'

# http://stackoverflow.com/a/14824756
isMessageRtl: (message) ->
ltrChars = 'A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02B8\u0300-\u0590\u0800-\u1FFF'+'\u2C00-\uFB1C\uFDFE-\uFE6F\uFEFD-\uFFFF'
rtlChars = '\u0591-\u07FF\uFB1D-\uFDFD\uFE70-\uFEFC'
rtlDirCheck = new RegExp "^[^#{ltrChars}]*[#{rtlChars}]"

return rtlDirCheck.test message

isMessageTooLong: (message) ->
message?.length > this.messageMaxSize

Expand Down

0 comments on commit eff538b

Please sign in to comment.