1
0
mirror of https://github.com/wbbaddons/Tims-Chat.git synced 2024-10-31 14:10:08 +00:00

Allow autocompletion of commands

This commit is contained in:
Tim Düsterhus 2013-06-01 14:06:55 +02:00
parent 0cdcffc65a
commit 9bb3a337a7

View File

@ -177,10 +177,17 @@ The the word the caret is in will be passed to `autocomplete` and replaced if a
return if toComplete.length is 0
console.log "Autocompleting '#{toComplete}'"
regex = new RegExp "^#{WCF.String.escapeRegExp(toComplete)}", "i"
users = (username for user in $('.timsChatUser') when regex.test(username = $(user).data('username')))
toComplete = users[autocomplete.offset++ % users.length] + ', ' if users.length isnt 0
if beforeComplete is '' and toComplete.substring(0, 1) is '/'
regex = new RegExp "^#{WCF.String.escapeRegExp toComplete.substring 1}", "i"
# TODO: Proper command list
commands = (command for command in [ 'gmute', 'gban', 'ban', 'mute', 'whisper', 'where', 'info' ] when regex.test command)
toComplete = '/' + commands[autocomplete.offset++ % commands.length] + ' ' if commands.length isnt 0
else
regex = new RegExp "^#{WCF.String.escapeRegExp toComplete}", "i"
users = (username for user in $('.timsChatUser') when regex.test(username = $(user).data('username')))
toComplete = users[autocomplete.offset++ % users.length] + ', ' if users.length isnt 0
input.val "#{beforeComplete}#{toComplete}#{afterComplete}"
input.setCaret (beforeComplete + toComplete).length