gpt4 book ai didi

javascript - 王牌 : move caret into the pair of brackets after custom autocompletion

转载 作者:行者123 更新时间:2023-11-30 20:44:07 25 4
gpt4 key购买 nike

我是 Ace 的新手,我正在用它制作一个 JavaScript 编辑器。我在编辑器中添加了自动完成器:

var functionCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var funcList = ["foo", "bar"]
callback(null, funcList.map(function(word) {
return {
caption: word,
value: word + "()",
meta: "Custom Functions"
};
}));
}
}
editor.completers.push(functionCompleter);

自动完成后:

但是我希望插入符号在完成后位于圆括号之间,如下所示:

这样添加函数参数会更方便

有没有办法用 JavaScript 来做?谢谢

最佳答案

自动完成后,您可以使用Ace 的goToLine 函数将光标设置在括号之间。

//Once you Insert the brackets ()
var pos = editor.selection.getCursor(); //Take the latest position on the editor
editor.gotoLine(pos.row + 1, pos.column + 2); //This will set your cursor in between the brackets

对于回调,您可以使用自动完成 insertMatch

var functionCompleter = {
getCompletions: function(editor, session, pos, prefix, callback) {
var funcList = ["foo", "bar"]
callback(null, funcList.map(function(word) {
return {
caption: word,
value: word + "()",
meta: "Custom Functions"

completer: {
insertMatch: function(editor, data) {
console.log(data.value); // This should give the completed keyword
// Here you can get the position and set the cursor
}
}
};
}));
}
}
editor.completers.push(functionCompleter);

关于javascript - 王牌 : move caret into the pair of brackets after custom autocompletion,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48930561/

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