在摩纳哥编辑器中滚动到一行

Scroll to line in Monaco editor

我看到有一种方法可以在 monaco 编辑器中设置 scrolltop。如何滚动到特定行而不是特定像素?

如文档中所示:https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.icodeeditor.html

滚动到顶部,以像素为单位:

editor.setScrollPosition({scrollTop: 0});

滚动到特定行:

editor.revealLine(15);

滚动到特定行,使其在编辑器的中央结束:

editor.revealLineInCenter(15);

移动当前活动行:

editor.setPosition({column: 1, lineNumber: 3});

我只想补充一点,如果你想滚动到最后一行,你可以使用

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