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

问题描述 投票:0回答:1

试图为拼写检查模块实现自定义showHint调用。我跟着docs但是调用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/

javascript plugins editor wysiwyg codemirror
1个回答
2
投票

好的,根据文档找出我的问题:

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

他们必须从传递给fromto函数返回,而不是将listshowHint(options)hint传递给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);
});
© www.soinside.com 2019 - 2024. All rights reserved.