20

I see there is a way to set scrolltop in monaco editor. How would one scroll to a specific line instead of a specific pixel?

0

3 Answers 3

52

As in the docs: https://microsoft.github.io/monaco-editor/typedoc/interfaces/editor.ICodeEditor.html

Scroll to top, in px:

editor.setScrollPosition({scrollTop: 0});

Scroll to a specific line:

editor.revealLine(15);

Scroll to a specific line so it ends in the center of the editor:

editor.revealLineInCenter(15);

Move current active line:

editor.setPosition({column: 1, lineNumber: 3});
Sign up to request clarification or add additional context in comments.

2 Comments

revealLine and revealLineInCenter does nothing in my case.
The link does not work
8

I just want to add that if you want to scroll to the last line, you can use

editor.revealLine(editor.getModel().getLineCount())

Comments

0
editor.getPosition()

can be used to get the line and column of the cursor's current position.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.