gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 18:38:30 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com