Search code examples
javascriptace-editor

Ace Editor How To Get Selected Lines


I am trying to get the selected information from Ace Editor. I found the below function that allows you to get the selected text. However, I would like to get the lines of that selection.

editor.getSelectedText()

In the below image I would expect to get back (rowStart: 5, rowEnd: 12) or something such as this.

Ace Editor

enter image description here

Update:

Wanted to post the exact code that ended up getting used for getting the first and last line in the selection.

var editorLines = editor.selection.getAllRanges();
var start = editorLines[0].start.row + 1;
var end = editorLines[0].end.row + 1;

Solution

  • use editor.selection.getRange() or editor.selection.getAllRanges() for multiselect