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

Joh*_*ton 6 javascript typescript monaco-editor

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

nac*_*oab 16

与文档中一样:https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.icodeeditor.html

滚动到顶部,在px中:

editor.setScrollPosition({scrollTop: 0});
Run Code Online (Sandbox Code Playgroud)

滚动到特定行:

editor.revealLine(15);
Run Code Online (Sandbox Code Playgroud)

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

editor.revealLineInCenter(15);
Run Code Online (Sandbox Code Playgroud)

移动当前活动行:

editor.setPosition({column: 1, lineNumber: 3});
Run Code Online (Sandbox Code Playgroud)


Rom*_*om1 6

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

editor.revealLine(editor.getModel().getLineCount())
Run Code Online (Sandbox Code Playgroud)