mez*_*ano 7 javascript typescript monaco-editor
我想在monaco编辑器的实例中设置缩进宽度(在空格中).
到目前为止,我已经能够通过在IEditorOptions初始化期间传入任何选项来自定义许多选项.也可以稍后使用updateOptions编辑器实例上的方法自定义这些选项,如以下示例所示:
// Many settings can be applied at initialization
var editor = monaco.editor.create(
document.getElementById("editor"), {
language: "html",
value: "<p>Hello World!</p>",
});
// ... they can also be changed later ...
editor.updateOptions({
lineNumbers: true,
})
// ... however, tabSize is not among the settings that can be modified --
// the following has no effect:
editor.updateOptions({
tabSize: 2,
})
Run Code Online (Sandbox Code Playgroud)
但是,该接口中没有定义该tabSize设置,而是一个单独的接口,我无法找到绑定(代码搜索只找到接口定义).FormattingOptions
你能帮我调整一下这个设置吗?我的猜测是我误解了(其他优秀的)编辑器文档,所以任何导航它的帮助都会非常有帮助.
与往常一样,任何想法和提示都非常受欢迎.非常感谢你考虑这个问题!
答案刚刚在相应的GitHub问题中讨论过.诀窍不是直接更新编辑器上的选项,而是更新底层模型.要扩展上面的剪辑:
const editor = monaco.editor.create(
document.getElementById("editor"), {
language: "html",
value: "<p>Hello World!</p>",
});
editor.getModel().updateOptions({ tabSize: 2 })
Run Code Online (Sandbox Code Playgroud)
这适用于摩纳哥游乐场的 me(™).
所有这一切归功于摩纳哥开发者 - 我非常喜欢他们的编辑,这进一步改善了它.
| 归档时间: |
|
| 查看次数: |
1535 次 |
| 最近记录: |