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

标签 javascript plugins editor wysiwyg codemirror

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

最佳答案

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

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

必须返回它们,而不是将 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);
});

关于javascript - CodeMirror 自定义 showHint() 调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36553748/

相关文章:

javascript - 替换行的内容(在 ace.editor 中)并覆盖它

java - Heroku Postgres : Getting started in Eclipse

DrRacket 编辑器的性能问题

c++ - 如何在eclipse调用层次结构 View 中显示调用函数的文件名

javascript - 基于插件的 GUI 中的模型- View -演示者生命周期管理

css - 可视化 CSS 结构并比较它们的东西

javascript - 如何在客户端从服务器(Node JS 和 Express)接收和使用 JSON 对象?

javascript - 9999.9999 或 9999 或 9999 的正则表达式 :9999

javascript - jQuery Datatable 在更新第 2 部分后将 CSS 添加到单元格

plugins - 如何使用 automake/autoconf/libtool 为 exe 生成导入库?