Codemirror自动完成插件事件绑定

时间:2013-09-13 20:00:43

标签: javascript autocomplete codemirror

有没有人知道如何将“显示”,“选择”和“关闭”事件绑定到showmirror的show hint addon的完成对象?我想绑定这些事件的原因是因为我想自动定位完成列表。不知何故,当光标位于页面的最底部时,列表不在窗口中。但是当我查看codemirror站点上的完成演示时。它没有这个问题,它是自动定位的。请帮助,谢谢

以下是codemirror站点的文档。它是如何运作的并不是很清楚。并且没有像jQuery doc那样的示例或演示。

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.

2 个答案:

答案 0 :(得分:0)

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

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

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

答案 1 :(得分:0)

我不确定你的答案,但我遇到了同样的问题。 “拾取”信号(和其他完成信号)似乎是针对“数据”发出的,而不是“编辑”对象。

以下是订阅“pick”事件的简单方法,例如:

        var completion = cm.state.completionActive;
        console.log('handling the completion object:', completion);
        var pick = completion.pick;
        completion.pick = function (data, i) {
            var completion = data.list[i];
            console.log('picked', data, completion);
            pick.apply(this, arguments);
        }