                 else
                     return ''
 
-        # We build a stack of the query.
+         # Get the last key if the last element is a key of an object
+         get_last_key: (stack) =>
+            if (not stack?) or stack.length is 0
+                return ''
+
+            element = stack[stack.length-1]
+            if element.body?
+                return @get_last_key(element.body)
+            else
+                if element.complete is false and element.key?
+                    return element.key
+                else
+                    return ''
+
+       # We build a stack of the query.
         # Chained functions are in the same array, arguments/inner queries are in a nested array
         # element.type in ['string', 'function', 'var', 'separator', 'anonymous_function', 'object', 'array_entry', 'object_key' 'array']
         extract_data_from_query: (args) =>


                char_to_insert = String.fromCharCode event.which
                if char_to_insert?
                    if event.type isnt 'keypress' # We catch keypress because single and double quotes have not the same keyCode on keydown/keypres #thisIsMadness
                        return true

                    if char_to_insert is '"' or char_to_insert is "'"
                        num_quote = @count_char char_to_insert
                        next_char = @get_next_char()
                        if next_char is char_to_insert # Next char is a single quote
                            if num_quote%2 is 0
                                if @last_element_type_if_incomplete(stack) is 'string' # We are at the end of a string and the user just wrote a quote 
                                    @move_cursor 1
                                    event.preventDefault()
                                    return true

                        @codemirror.replaceSelection(char_to_insert+@codemirror.getSelection()+char_to_insert)
                        event.preventDefault()
                        return true

                if event.which is 8 # Backspace
                    if event.type isnt 'keydown'
