3

In Avalonedit, how do I get the line number of the very top line that is visible to the user?

I believe I'm supposed to make some use out of VisualLines but it isn't helping.

TtT23
  • 6,876
  • 34
  • 103
  • 174

1 Answers1

3

You can use GetDocumentLineByVisualTop:

int firstLine = textView.GetDocumentLineByVisualTop(textView.ScrollOffset.Y).LineNumber;

textView.VisualLines[0].FirstDocumentLine.LineNumber would work as well, but you have to be careful there - the visual lines collection can be invalid if a redraw was requested but not performed yet (see VisualLinesValid/EnsureVisualLines()).

Daniel
  • 15,944
  • 2
  • 54
  • 60
  • 2
    to clarify; `GetDocumentLineByVisualTop` can be found at `textEditor.TextArea.TextView.GetDocumentLineByVisualTop` – Chad Carisch Jul 07 '14 at 16:21