Javascript 如何在ACE编辑器中将光标移动到行尾?

Javascript 如何在ACE编辑器中将光标移动到行尾?,javascript,html,ace-editor,Javascript,Html,Ace Editor,在Javascript文件中,我有以下代码行: editor.focus(); // To focus the ace editor var n = editor.getSession().getValue().split("\n").length - 2; editor.gotoLine(n); 这将聚焦ACE编辑器,移动到最后一行,并上升两行。当它向上移动这两行时,它也会将光标移动到该行的前面。模拟某人按Home键 Q:如何将光标移动到行尾?或直接从以下位置模拟结束键: 您想使用方法n

在Javascript文件中,我有以下代码行:

editor.focus(); // To focus the ace editor
var n = editor.getSession().getValue().split("\n").length - 2;
editor.gotoLine(n); 
这将聚焦ACE编辑器,移动到最后一行,并上升两行。当它向上移动这两行时,它也会将光标移动到该行的前面。模拟某人按Home键

Q:如何将光标移动到行尾?或直接从以下位置模拟结束键:

您想使用方法
navigateLinend()
。因此,在你的情况下:

editor.focus(); // To focus the ace editor
var n = editor.getSession().getValue().split("\n").length - 2;
editor.gotoLine(n); 
editor.navigateLineEnd() // Navigate to end of line

gotoline
接受两个参数,一个用于行,一个用于列

var row = editor.session.getLength() - 1
var column = editor.session.getLine(row).length // or simply Infinity
editor.gotoLine(row + 1, column)
请注意,
gotoLine
可以使用动画将所选内容滚动到视图中,如果您不希望,可以使用

editor.selection.moveTo(row, column)
相反

完全模拟用户按下end use时处理结束键的方式


第一个
gotoLine
中有一个打字错误。其他的拼写正确。
editor.execCommand("gotolineend")