Re: [ace] Get selected text from ace editor

1,911 views
Skip to first unread message

Harutyun Amirjanyan

unread,
Mar 30, 2013, 4:31:42 AM3/30/13
to ace-d...@googlegroups.com
use
editor.session.getTextRange(editor.getSelectionRange())
or
editor.getCopyText()

When multiple ranges are selected getCopyText returns text in all
ranges joined with \n, first method will return only text in last
added range.

Also it may be worth to add
editor.getSelectedText = function() {
this.session.getTextRange(this.getSelectionRange())
}
to editor since this is often needed

Steve Ottoz

unread,
Apr 1, 2013, 12:08:07 AM4/1/13
to ace-d...@googlegroups.com
Thanks. 

That's exactly what I needed.

Only had to add the "return" to make the function work.

editor.getSelectedText = function() { 
    return this.session.getTextRange(this.getSelectionRange());
}

Steve

Tom Doan

unread,
Aug 12, 2015, 3:54:09 AM8/12/15
to Ajax.org Cloud9 Editor (Ace)
You should also be able to do this: editor.getSelection();

Harutyun Amirjanyan

unread,
Aug 12, 2015, 5:59:16 AM8/12/15
to ace-d...@googlegroups.com
@Tom editor.getSelection(); returns editor.selection object and cannot be used to get the text

there is editor.getSelectedText() method which returns selected text or in case of multiple selection ranges text in all ranges joined with newlines


Tom Doan

unread,
Aug 13, 2015, 4:03:36 AM8/13/15
to Ajax.org Cloud9 Editor (Ace)
@Harutyun Amirjanyan I'm confused because the API reference states:

getSelection() ->  String

So doesn't this mean it returns a string?

Harutyun Amirjanyan

unread,
Aug 18, 2015, 11:07:47 AM8/18/15
to ace-d...@googlegroups.com
> So doesn't this mean it returns a string?

that's a bug in api documentation.
thanks for reporting
Reply all
Reply to author
Forward
0 new messages