Posts

Showing posts with the label Codemirror

Codemirror Autocomplete After Any Keyup?

Answer : For version 5.7 neither of the previously proposed solutions work fine for me (and I think they have bugs even for earlier versions). My solution : myCodeMirror.on("keyup", function (cm, event) { if (!cm.state.completionActive && /*Enables keyboard navigation in autocomplete list*/ event.keyCode != 13) { /*Enter - do not open autocomplete list just after item has been selected in it*/ CodeMirror.commands.autocomplete(cm, null, {completeSingle: false}); } }); How it works: This opens autocomplete popup only if it is not opened yet (otherwise keyboard-navigation would have caused reopening the popup with 1st item selected again). When you click Enter you want popup to close so this is special case of a character which shouldn't trigger autocompletion (you may consider a case when you want to show antocompletion for empty line though). Then last fix is setting completeSingle: false which ...