From 9bb3a337a7b7d78b275e07d2962c605bb7e1fea4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 1 Jun 2013 14:06:55 +0200 Subject: [PATCH] Allow autocompletion of commands --- file/js/be.bastelstu.Chat.litcoffee | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/file/js/be.bastelstu.Chat.litcoffee b/file/js/be.bastelstu.Chat.litcoffee index 6097e1e..beffda9 100644 --- a/file/js/be.bastelstu.Chat.litcoffee +++ b/file/js/be.bastelstu.Chat.litcoffee @@ -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