在摩纳哥编辑器中禁用缩进指南

问题描述

我已经使用 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);

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...