how I can trigger the autocomplete on codemirror if the character before the cursor is “.”?

I am using codemirror , I knew how I can to do autocomplete when I press “.” but I need to do autocomplete when the character before the cursor is “.” , so if I have the textarea :

test. Note : when I run then the word "test." write on codemirror , but the codemirror did not do autocomplete because I did not press the character "." this is my code : CodeMirror.commands.autocomplete = function(cm) { CodeMirror.showHint(cm, CodeMirror.hint.anyword); };
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
matchBrackets: true,
mode: "text/x-stsrc",
indentUnit: 4,
autoCloseBrackets: true,
highlightSelectionMatches: true,
styleActiveLine: true,
extraKeys: {
    "Ctrl-Space": "autocomplete" ,
    "Ctrl-Space":function(cm){  CodeMirror.showHint(cm, CodeMirror.hint.anyword); }, 
    "'.'" : function(cmm){ CodeMirror.showHint(cmm, CodeMirror.hint.anyword);},


autohint: true,
readOnly: false,
lineWrapping: true,


editor.on("blur", function(codeMirror) {; });


var orig = CodeMirror.hint.anyword;

CodeMirror.hint.anyword = function(cm) {
var inner = orig(cm) || { from: cm.getCursor(), to: cm.getCursor(), list: []};

return inner;
and this is my code on js :,js,output
any help ? how I can to do autocomplete if the character before the cursor is “.” ? thanks in advance

1 Like