javascripteventscodemirror

CodeMirror OnSelect event not working


See edit at the end


I've just started to use CodeMirror for a project and I'm facing a problem that I don't understand at all.

The problem is about to handling CodeMirror's events, specifically on the "select" event, since I'm handling the "change" event without problems I cannot guess what's happening.

Let's see some code; I'm wrapping a CodeMirror object into another object, it looks similar to this:

function expressionEditor(config)
{
    jQuery('#divEditor').append('<textarea id="expression"/>');

    this.editor = CodeMirror.fromTextArea(document.getElementById('expression'),
    {
      mode:        'custom',
      lineNumbers: true,
      extraKeys:   {'Ctrl-Space': 'autocomplete'}
    });

    this.OnChange = function(instance, object)
    {
      if (object.text[0] === '.')
      {
        CodeMirror.showHint(this.editor, CodeMirror.hint.custom);
      }
    };

    this.OnSelectHint = function(completion, Element)
    {
      alert(completion + ' : ' + Element);
    };

    CodeMirror.on(this.editor, 'change', jQuery.proxy(this.OnChange, this));

    CodeMirror.on(this.editor, 'select', jQuery.proxy(this.OnSelectHint, this));
}

As I said, the event "change" works as expected, when I write a dot into the editor it calls the function this.OnChange which summons the hint list, but when I navigate over the suggested hints this.OnSelectHint function is never called (no alert pops up on the navigator).

According to the CodeMirror documentation about "select" event, the callback must be "Fired when a completion is selected. Passed the completion value (string or object) and the DOM node that represents it in the menu".

Since other events are working, I'm totally lost... any clue on what's happening?


Edit

As said by Marijn, there's no "select" event in CodeMirror; the "select" event is from the show-hint CodeMirror Addon. Just for knowing:


Solution

  • There is no "select" event in the CodeMirror API. Thus, listening for it will do absolutely nothing.