Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ace Editor get value on single line

I am trying to get value on single line on Ace editor.

According to Ace Editor documentation:

  • gotoLine() to navigate to single line
  • getLine() to get single line
  • getLines() to get multiple lines

Here is what I tried:

var html = ace.edit("html");

html.getSession().setMode("ace/mode/html");
html.setTheme("ace/theme/eclipse");
html.setPrintMarginColumn(false);
html.resize();

var line4 = html.gotoLine(4);
var getfour = html.getLine(4);
var getfoureight = html.getLines(4,8);

gotoLine() works. getLine() and getLines() doesn't work.

What am I doing wrong?

like image 753
Olalekan Avatar asked Sep 14 '14 16:09

Olalekan


1 Answers

getLine and getLines are functions on the session, so you need to call them like

var editor = ace.edit("html");
editor.setValue("line0 \n line1 \n line2 \n line3")
editor.session.getLine(2) // returns " line2 "
editor.session.getLines(1, 2) // returns [" line1 ", " line2 "]
like image 163
a user Avatar answered Sep 18 '22 06:09

a user