简体   繁体   中英

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?

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});

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM