CodeMirror自定义showHint()调用不会'不起作用

CodeMirror custom showHint() call doesn't work

本文关键字:不起作用 调用 自定义 showHint CodeMirror      更新时间:2024-04-21

正在尝试为拼写检查模块实现自定义showHint调用。我已经遵循了文档,但调用editor.showHint似乎没有任何作用,并返回undefined

我想我少了些什么。这是我要测试的沙箱代码:

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/

好的,根据文档,解决了我的问题:

查找提示是通过提示函数(提示选项)完成的,该函数采用编辑器实例和选项对象,并返回{list,from,to}对象

必须从传递到showHinthint函数返回fromtolist,而不是将它们传递给showHint(options)

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);
});