javascript - Codemirror 自动完成插件事件绑定(bind)

标签 javascript autocomplete codemirror

有谁知道如何将“shown”、“select”和“close”事件绑定(bind)到codemirror的showhint插件的完成对象上?我想绑定(bind)这些事件的原因是因为我想自动定位完成列表。不知怎的,当光标真正位于页面底部时,列表就离开了窗口。但是当我在 codemirror 网站上查看完成演示时。它没有这个问题,并且它是自动定位的。请帮忙,谢谢

这是来自 codemirror 站点的文档。目前还不清楚它是如何工作的。并且没有像 jQuery 文档那样的示例或演示。

The following events will be fired on the completions object during completion:
"shown" ()
Fired when the pop-up is shown.
"select" (completion, Element)
Fired when a completion is selected. Passed the completion value (string or object) and       the DOM node that represents it in the menu.
"close" ()
Fired when the completion is finished.
This addon depends styles from addon/hint/show-hint.css. Check out the demo for an  example.

最佳答案

好的,我自己通过阅读、比较和调试CodeMirror源码解决了这个问题。我认为这是 CodeMirror 的一个错误。基本上,下载版本的 show-hint.js 中有一行与演示链接文件中的不同。

您需要将代码移至第 169 行下方和“var box”初始化上方。以便“var box”在调用getBoundingClientRect()后能够得到正确的数字。希望他们能够尽快解决这个问题。

(options.container || document.body).appendChild(hints);

关于javascript - Codemirror 自动完成插件事件绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18794310/

相关文章:

javascript - 如何使用 jquery 定位同级 div 的子级

javascript - Fabricjs 中的箭头

python - emacs elpy/jedi 代码完成 : popup window not working properly

javascript - 根据自动完成的数据自动填充另一个文本字段

javascript - HTML/jQuery onload/load 在 iOS 上未执行

javascript - 使用 <select multiple> 来过滤 div

bash - 复制 bash 完成(不复制实际代码)

codemirror - 如何在 codemirror 编辑器中使用 cypress .type() 键入?

javascript - 如何在 Codemirror 中使用正则表达式来匹配段落的第一个和最后一个单词?

php - CodeMirror 保存自己 onBlur