Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scroll to line in Monaco editor

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?

like image 847
Johnston Avatar asked Jul 15 '17 22:07

Johnston


2 Answers

As in the docs: https://microsoft.github.io/monaco-editor/api/interfaces/monaco.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});
like image 175
nachoab Avatar answered Nov 06 '22 11:11

nachoab


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

editor.revealLine(editor.getModel().getLineCount())
like image 4
Rom1 Avatar answered Nov 06 '22 11:11

Rom1