How to get the line number of the first visible line in the Monaco editor at the current viewport scroll?

Viewed 527

I'm building a side-by-side preview, and so I need to get the topmost visible line number in the editor.

I think I can get the top pixel scroll with:

  editor.onDidScrollChange(function (e) {
    console.error(e.scrollTop);
  });

and the cursor line number with:

editor.getPosition().lineNumber

but I didn't manage the top visible line.

1 Answers

Ah, after searching some more I found getVisibleRanges:

  editor.onDidScrollChange(function (e) {
    console.error(editor.getVisibleRanges()[0].startLineNumber);
  });

This shows the number of the first fully visible line.

Related