                     if previous_char of @matching_opening_bracket
                         next_char = @get_next_char()
                         if next_char is @matching_opening_bracket[previous_char]
-                            @remove_next()
-                            return true
+                            num_not_closed_bracket = @count_not_closed_brackets previous_char
+                            if num_not_closed_bracket <= 0
+                                @remove_next()
+                                return true
                     # If the user remove the first quote of an empty string, we remove both quotes
                     else if previous_char is '"' or previous_char is "'"
                         next_char = @get_next_char()
                         if next_char is previous_char and @get_previous_char(2) isnt '\\'
-                            @remove_next()
-                            return true
+                            num_quote = @count_char char_to_insert
+                            if num_quote%2 is 0
+                                @remove_next()
+                                return true
                     return true
 
                 char_to_insert = String.fromCharCode event.which

                position: 0

            @pair_char(event, stack)
            # If a selection is active, we just catch shift+enter
            if @codemirror.getSelection() isnt ''
                @hide_suggestion_and_description()

                    return false
                else
                    return true

            result =
                status: null
