【问题标题】:CodeMirror custom showHint() call doesn't workCodeMirror 自定义 showHint() 调用不起作用
【发布时间】:2016-04-11 16:03:39
【问题描述】:

尝试为拼写检查模块实现自定义 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】:

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

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

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

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

    【讨论】:

      猜你喜欢
      • 2011-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-07
      • 1970-01-01
      相关资源
      最近更新 更多