问题描述
我已经使用 Monaco Editor 库完成了一个应用程序,该库允许更改编辑器的语言(如here)。除了语言为plaintext
之外,我想提供缩进指南。可能吗?我可以在主题中隐藏缩进参考线,但是我不知道如何有条件地隐藏它们。我没有找到任何选择。
解决方法
您可以通过 renderIndentGuides
属性进行设置。请参阅:https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditoroptions.html#renderindentguides
下面显示了一个简单的摩纳哥游乐场示例来演示这一点。请注意,您可以在创建编辑器后使用 updateOptions
设置此属性。
var editor = monaco.editor.create(document.getElementById("container"),{
value: [
"function hello() {","\tfor (let i = 0; i < 2; i++) {","\t\tconsole.log('Hello world!');","\t}","}",].join("\n"),language: "javascript",renderIndentGuides: false
});
setTimeout(function() {
editor.updateOptions({
renderIndentGuides: true
});
},3000);