         return false
 
     insert_text: (add) =>
-        print "insert", add
         [text, [start, end], s] = @get_text_state()
-        text = text[..start] + add + text[end..]
+        text = text[..start-1] + add + text[end..]
         start += add.length
         end += add.length
         print [text, [start, end], s]


    autocomplete: =>
        [text, [start, end], s] = @get_text_state()
        string = text.substr(0, start)
        at = text[start]
        string = string.match(/\w+$/)
        print "ac", at, string
        if (not at or at.match("\s")) and string
            options = {}
            words = text.split(/\W+/).sort()
            if words

        @con = new Connection()
        @filename = "foo"

        @tab_width = 4

        # grab common elements
        @$doc = $(document)
