Search code examples
javascriptpluginseditorwysiwygcodemirror

CodeMirror custom showHint() call doesn't work


Attempting to implement a custom showHint call for a spellcheck module. I've followed the docs but calling editor.showHint appears to do nothing and returns undefined.

I figure there is something I am missing. Here is my sandbox code to test:

editor.on('cursorActivity', function() {
    var options = {
    from: editor.getDoc().getCursor(),
    to: editor.getDoc().getCursor(),
    list: ['foo', 'bar', 'baz']
  };
  editor.showHint(options);
});

http://jsfiddle.net/3wvcudqt/3/


Solution

  • OK, figured out my problem, per the docs:

    Finding hints is done with a hinting functions (the hint option), which is a function that take an editor instance and options object, and return a {list, from, to} object

    Instead of passing from, to, and list into showHint(options), they must be returned from a hint function passed into showHint.

    http://jsfiddle.net/3wvcudqt/4/

    editor.on('cursorActivity', function() {
      var options = {
        hint: function() {
          return {
            from: editor.getDoc().getCursor(),
              to: editor.getDoc().getCursor(),
            list: ['foo', 'bar']
          }
        }
      };
      editor.showHint(options);
    });