Johnston Johnston - 2 years ago 150
TypeScript Question

Scroll to line in Monaco editor

I see there is a way to set

in monaco editor. How would one scroll to a specific line instead of a specific pixel?

Answer Source

As in the docs:

Scroll to top, in px:

editor.setScrollPosition({scrollTop: 0});

Scroll to a specific line:


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


Move current active line:

editor.setPosition({column: 1, lineNumber: 3});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download