【发布时间】:2016-12-29 01:15:57
【问题描述】:
问题:有没有办法在编辑器完全加载后执行 Ace 编辑器命令?
我正在尝试在页面加载/重新加载后设置 Ace 编辑器的光标位置。编辑器的内容在加载编辑器时在回调之一中设置。在此处设置光标位置不起作用,因为仍在加载编辑器的其余部分(如 VirtualRenderer),它会将编辑器内容重置为从顶部显示。
下面的代码有效,它设置内容、代码折叠和光标位置。但是,光标最终离开屏幕,内容从顶部显示。编辑器完全加载后,我希望它滚动到光标。
//Put the content of the file into the editor
editor.session.setValue(content);
//Restore code folds
for(var i = 0; i < folds.length; i++) {
editor.session.addFold("...",folds[i]);
}
//Put the cursor in the correct place
editor.gotoLine(cursor.row,cursor.column, true);
editor.renderer.scrollToRow(cursor.row);
【问题讨论】:
-
编辑器加载后,尝试editor.focus(),它的设置焦点在你的编辑器上,然后你可以使用editor.moveTo()或editor.goToLine()来调整位置编辑器到所需的光标位置。
标签: javascript html ace-editor