3

Is there a function in RichTextFX to get the actual line number where the curser?

Github: RichTextFX

Luke
  • 59
  • 7

2 Answers2

6

You can get the index of the caret ("cursor") with

int offset = textArea.getCaretPosition();

and then convert to a TwoDimensional.Position with

Position pos = textArea.offsetToPosition(offset);

From there, pos.getMajor() is the paragraph (line) number (and pos.getMinor() is the index of the caret within the line).

James_D
  • 201,275
  • 16
  • 291
  • 322
  • Do you mean textArea.getCaretColumn()? Also, upvoted because you got me 99% of the way there. – Steve Jan 11 '19 at 19:17
0

You can get the current paragraph index or line number with:

codeArea.getCaretSelectionBind().getParagraphIndex();