繁体   English   中英

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

[英]Setting Ace Editor Cursor Position After Page Load

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

你能试试吗?

//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.focus();
editor.gotoLine(cursor.row,cursor.column, true);
editor.renderer.scrollToRow(cursor.row);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM