Using both autoCloseBrackets and autocomplete


I have both the autoCloseBrackets and autocomplete functionality enabled (I’m using the hintOptions option with an async hintFunction). Both work fine, but I’m trying to use them together.

My desired functionality is that a user would type an open quote " or ', the autoCloseBracketsEvent would fire, closing the quote correctly, and then autocomplete would fire, showing the autocomplete pane.

The state transitioning of the editor would be like this ("|" indicates the cursor) :

start ->                                   | 
user types open quote ->                   '|
autoCloseBrackets closes the quote ->      '|' 
autocomplete (through key event fires) ->  '|(autocomplete pane here)'

The problem is that I need the autoCloseBrackets event to fall through (return CodeMirror.Pass). The fact that I want autocomplete to fire is incidental, more generally what I want is to have the ability to trigger an event (through a keyMap binding) AFTER autoCloseBrackets finishes that uses the same keyPress that autoCloseBrackets used.

The obvious hacky way to do that is to iterate through cm.state.keyMaps and find the event associated with ’ or " and modify it directly, but that’s terrible.

Is there / could there be a supported way for autoCloseBrackets to do what I’m looking for?

Thanks for your help!

How are you triggering the autocomplete? (I.e. from which event.)

To initiate autocomplete I’m calling


To bind ctrl + space I’m doing

cm.editor.setOption("extraKeys", {"Ctrl-Space": /*function with contents as above*/});

To bind ', I first tried adding it with extraKeys but that didn’t work because autoCloseBrackets was eating the event. If I disabled autoCloseBrackets, the autocomplete trigger worked on ’

I see the problem now, yes. One workaround would be to add a higher-precedence keymap (using addKeyMap after initializing the editor) that listens for ' keypresses, always returns CodeMirror.Pass (so that the autoclosebrackets handler does get a chance to run) but triggers an autocomplete after a short timeout.