ACE编辑器 - >默认情况下会加载已加载的脚本

时间:2013-11-21 03:06:37

标签: ace-editor

我正在将脚本加载到Ace编辑器中,并且在渲染时,整个脚本会突出显示,好像有人做了ctrl + a(全选)。如何使内容“未被选中”......似乎它应该默认以这种方式工作。

根据文档,似乎我可以解决:

session.getSelection().clearSelection();

...并且基于this SO question,似乎我也可以这样做:

editor.setValue(str, -1) // moves cursor to the start
editor.setValue(str, 1) // moves cursor to the end

既不工作......

2 个答案:

答案 0 :(得分:0)

您可以删除以下部分内容,但如果没有看到您的代码,很难说,但这绝对应该涵盖它。

editor.setValue('hello world');
editor.clearSelection(1);
editor.gotoLine(1);
editor.getSession().setScrollTop(1);
editor.blur();
editor.focus();

答案 1 :(得分:0)

我遇到了同样的问题,并且我以这种方式解决了问题

editor.once('focus', function(){
  editor.selection.clearSelection()
})

因此,似乎在某些情况下,编辑器尚未准备好接受命令。