在 Ace 编辑器中的多个光标上执行方法

Performing methods on multiple cursor in Ace Editor

本文关键字:光标 执行 方法 Ace 编辑器      更新时间:2023-09-26

我正在使用 Ace 编辑器,我只能在单个游标上执行功能,而不能在多个游标上执行功能例如

 editor.navigateLineStart(); 

如果有一个游标,则将光标移动到行首,但如果有多个游标则不会

这可以通过键入(左主页)手动完成因为下面的代码在文档中 ace.js,但我不明白如何将多选操作设置为"forEach",或者这是否有帮助

{name: "gotolinestart",
bindKey: bindKey("Alt-Left|Home", "Command-Left|Home|Ctrl-A"),
exec: function(editor) { editor.navigateLineStart(); },
multiSelectAction: "forEach",
readOnly: true
}

还有一个功能

 forEachSelection(String cmd, String args) 

http://ace.c9.io/#nav=api&api=editor为每个选择范围执行命令。但我不知道该输入什么参数我认为对于命令,输入是"Gotolinestart",但我也不确定我可以在一个游标上工作但不能用于多个游标的其他函数包括

editor.getSelection().selectLeft();
editor.navigateLeft(args.times);

在 ACE 编辑器中使用多个光标和选择的函数的任何示例都将非常有帮助。

似乎

文档中有一个错误,它应该说forEachSelection({exec:function}, arg:any)

arg可以是任何东西,它只是传递给cmd.exec

此外,它仅在有多个选择时才有效,因此您需要执行以下操作

if (editor.selection.rangeCount > 1)
    editor.forEachSelection({exec: function() {
        editor.editor.navigateLeft(10);
    }})
} else
    editor.editor.navigateLeft(10);

另一种方法是使用 execCommand

editor.execCommand({
    exec:function() {
        editor.selection.selectLeft()
    },
    multiSelectAction: "forEach"
})