Why I can not get the selected word i codemirror when I do autocomplete on the characer like “.”?

I am trying to get the selected word when I do autocomplete on codemirror , this is my code it work when the autocomplete trigger by press “ctrl_space” ( I selected word from drop down list and the value of completion is the selected word )

 extraKeys: {
                    "Ctrl-Space": "autocomplete",
                    "Ctrl-Space":function(cm){ 
                        CodeMirror.showHint(cm, CodeMirror.hint.anyword);
                        var completion = cm.state.completionActive.data;
                        alert(completion);
}

it work fine , But when I put the same code when I press “.” then the code not work (I selected word from drop down list but the value of completion is empty ) :

extraKeys: { "'.'": "autocomplete", "'.'":function(cm){ CodeMirror.showHint(cm, CodeMirror.hint.anyword); var completion = cm.state.completionActive.data; alert(completion); }

so what wrong ?

Your key handler is not letting the ‘.’ actually be inserted, becuase it ‘handles’ the key. You can return CodeMirror.Pass from the handler to indicate that the default behavior can go through, but you also probably don’t want to actually autocomplete until the ‘.’ has been added to the document.

(Also, binding the same key twice, as you’re doing in both of your examples, is meaningless.)

I try to return CodeMirror.Pass but my problem did not solved @marijn