Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ace Editor get current selected line number and text

Tags:

javascript

I'm currently using Ace Editor, but I couldn't find anything in the docs along the lines of retrieving the current selected line number and its text.

Any ideas?

like image 466
dk123 Avatar asked Jul 23 '14 08:07

dk123


2 Answers

First, define "selected line". Selection in ace may be set across multiple lines. If you mean "no selection is set, current line is line where cursor blinks:"

var currline = editor.getSelectionRange().start.row;
var wholelinetxt = editor.session.getLine(currline);

If you need exact selected text, see @parchment answer, I was about wrote the same, but it's not needed now.

like image 134
Tommi Avatar answered Oct 20 '22 09:10

Tommi


You can do this:

selectionRange = editor.getSelectionRange();

startLine = selectionRange.start.row;
endLine = selectionRange.end.row;

content = editor.session.getTextRange(selectionRange);
like image 30
parchment Avatar answered Oct 20 '22 07:10

parchment