var Tutu = Tutu || (function() {
    function suggestion_menu_visible() {
        return $('div.tt-menu').is(":visible");
    }

    function removeSuggestionMenu(e) {
        if (suggestion_menu_visible()) {
            var suggestions = $('div.tt-menu div.tt-suggestion');
            var cmdSegs = $('#message-input').val().split();

            if(suggestions.length == 1) {
                var lastCmdSeg = $.trim(cmdSegs[cmdSegs.length - 1]);
                var suggestion = $.trim(suggestions.text());
                if (lastCmdSeg == suggestion) {
                    $('.typeahead').typeahead('val', suggestion);
                    $('.typeahead').typeahead('close');
                }
            }
        }
    }

    function initHotkeyBindings() {
        var msg_box = $('#message-input')[0];
        Mousetrap(msg_box).bind('enter', function(e) {
            removeSuggestionMenu();
            if (!suggestion_menu_visible()) {
                console.log("menu is visible, ignore logic here");
            }
        });
    }

    function initTypeahead() {
        var commands = new Bloodhound({
            datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
            queryTokenizer: function(str) {
                if (str.endsWith(' ')) {
                    // don't show menu when enter whitespace
                    return ['_impossible_token_'];
                }
                // Only return the last word as query token
                return [].slice.call($.trim(str).split(/\W+/), -1);
            },
            prefetch: '/api/commands'
        });

        $('.typeahead').typeahead({
                hint: true,
                highlight: true,
                minLength: 1,
                menuConfig: {
                    position: 'top'
                }
            }, {
                name: 'commands',
                display: 'name',
                source: commands,
                templates: {
                    header: '<h3 class="suggestion-menu">Commands</h3>'
                }
            }
        );
    }

    function initFocus() {
        $('#message-input').focus();
    }

    $(function() {
        initHotkeyBindings();
        initTypeahead();
        initFocus();
    });

    // API
    return {};
})();

@@ -114,32 +114,217 @@
 sible%22);%0A    %7D%0A%0A
+    function buildSuggestionCmd(rawInput, suggestion) %7B%0A        var cmdSegs = rawInput.split(/%5CW+/);%0A        return %5B%5D.slice.call(cmdSegs, 0, -1).concat(%5Bsuggestion%5D).join(' ');%0A    %7D%0A%0A
     function rem
@@ -342,24 +342,24 @@
 onMenu(e) %7B%0A
-
         if (
@@ -469,23 +469,24 @@
     var 
-cmdSegs
+rawInput
  = $('#m
@@ -505,23 +505,64 @@
 ').val()
+;%0A            var cmdSegs = rawInput
 .split(
+/%5CW+/
 );%0A%0A    
@@ -830,16 +830,45 @@
 d('val',
+ buildSuggestionCmd(rawInput,
  suggest
@@ -871,16 +871,17 @@
 gestion)
+)
 ;%0A      
@@ -1325,24 +1325,502 @@
 peahead() %7B%0A
+        var initTabKeyed = function() %7B%0A            var rawInput;%0A            $('.typeahead').bind('typeahead:beforeselect typeahead:beforeautocomplete', function(e, suggestion) %7B%0A                rawInput = $('#message-input').val();%0A            %7D);%0A%0A            $('.typeahead').bind('typeahead:select typeahead:autocomplete', function(e, suggestion) %7B%0A                $('.typeahead').typeahead('val', buildSuggestionCmd(rawInput, suggestion.name));%0A            %7D);%0A        %7D;%0A%0A
         var 
@@ -2317,16 +2317,16 @@
 mmands'%0A
-
         
@@ -2322,32 +2322,57 @@
 s'%0A        %7D);%0A%0A
+        initTabKeyed();%0A%0A
         $('.type

Fix the logic he tabkeyed