Skip to content

Commit a797b7e

Browse files
committed
Complete username with tab. Close #159
1 parent 6ba5c3c commit a797b7e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

client/lib/chatMessages.coffee

+17
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ class @ChatMessages
110110
postGrowCallback: =>
111111
this.resize()
112112

113+
tryCompletion: (input) ->
114+
value = input.value.match(/[^\s]+$/)
115+
if value?.length > 0
116+
value = value[0]
117+
118+
re = new RegExp value, 'i'
119+
120+
user = Meteor.users.findOne username: re
121+
if user?
122+
input.value = input.value.replace value, '@' + user.username
123+
113124
keyup: (rid, event) ->
114125
input = event.currentTarget
115126
k = event.which
@@ -148,6 +159,12 @@ class @ChatMessages
148159
else
149160
this.send(rid, input)
150161
return
162+
163+
if k is 9
164+
event.preventDefault()
165+
event.stopPropagation()
166+
@tryCompletion input
167+
151168
if k is 27
152169
if this.editing.id
153170
event.preventDefault()

0 commit comments

Comments
 (0)