2

I am loading script into the Ace editor, and upon render, the entire script is highlighted as if someone did a ctrl+a (select all). How do make the contents "unselected" ... seems like it should work that way by default.

Based on documentation, it seems like I could workaround with:

session.getSelection().clearSelection();

... and based on this SO question, it seems I could also do this:

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

Neither work...

Community
  • 1
  • 1
Robert Christian
  • 18,218
  • 20
  • 74
  • 89
  • could you make a jsbin demo reproducing the problem, it seems to work fine http://jsbin.com/ojijeb/180/edit – a user Nov 21 '13 at 07:47
  • Yes I will, and thanks for the post. My context is ace plus ace-ui angular module, plus a directive wrapping that. So seeing that it works, I will probably find the solution in breaking this down to the bare elements. Stay tuned. – Robert Christian Nov 22 '13 at 02:28

2 Answers2

0

You may be able to remove some of the following, it's hard to say without seeing your code, but this should definitely cover it.

editor.setValue('hello world');
editor.clearSelection(1);
editor.gotoLine(1);
editor.getSession().setScrollTop(1);
editor.blur();
editor.focus();
Carl Smith
  • 3,025
  • 24
  • 36
0

I had the same problem, and I worked around it this way

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

So it seems that in some cases the editor is not ready yet to accept the command.

Nick
  • 138,499
  • 22
  • 57
  • 95
rejetto
  • 76
  • 1
  • 3