页面加载后设置Ace编辑器光标位置

时间:2016-12-29 01:15:58

标签: javascript html ace-editor

问题:编辑器完全加载后,有没有办法执行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);

1 个答案:

答案 0 :(得分:0)

你能试试吗

+