首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在页面加载后设置Ace编辑器光标位置

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

Stack Overflow用户
提问于 2016-12-29 01:15:57
回答 1查看 2.1K关注 0票数 2

问题:是否有一种方法可以在编辑器完全加载后执行Ace编辑器命令?

我试图在页面加载/重新加载之后设置Ace编辑器的光标位置。在加载编辑器时,将在其中一个回调中设置编辑器的内容。在这里设置光标位置不起作用,因为编辑器的其余部分仍在加载(如VirtualRenderer),它将编辑器内容重置为从顶部显示。

下面的代码工作,它设置内容,代码折叠,和光标的位置。然而,光标在屏幕上结束,从顶部显示内容。在编辑器完全加载之后,我希望它滚动到光标。

代码语言:javascript
复制
//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);
EN

回答 1

Stack Overflow用户

发布于 2017-09-30 15:20:22

你能试试这个吗?

代码语言:javascript
复制
//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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/41371947

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档