有谁知道如何将“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/