【问题标题】:Getting fontInfo from monaco-editor instance?从 monaco-editor 实例获取 fontInfo?
【发布时间】:2020-08-27 22:50:20
【问题描述】:

我正在尝试获取typicalFullwidthCharacterWidth 属性,该属性在FontInfomonaco.editor 类中可用。

如 monaco-editor 文档中所示:

https://microsoft.github.io/monaco-editor/api/classes/monaco.editor.fontinfo.html

在查看使用 options.get(...) 的 Minimap 组件时:

https://github.com/microsoft/vscode/blob/f74e473238aca7b79c08be761d99a0232838ca4c/src/vs/editor/browser/viewParts/minimap/minimap.ts#L108

可以公开吗?

【问题讨论】:

    标签: monaco-editor


    【解决方案1】:

    我找到了解决方案,你必须使用IEditor.getOption函数:

    var editor = monaco.editor.create(document.getElementById("container"), {
        value: "// ... some text content",
        language: "javascript",
    });
    
    // https://github.com/Microsoft/monaco-editor/blob/master/monaco.d.ts#L3667
    const EDITOR_OPTION_FONT_INFO = 34;
    
    // Get the font info from options using the fontInfo option id
    const fontInfo = editor.getOption(EDITOR_OPTION_FONT_INFO);
    
    console.log(fontInfo) // Output: {zoomLevel: 0, fontFamily: "Roboto", fontWeight: "400", fontSize: 14, fontFeatureSettings: ""liga" off, "calt" off", …}
    

    【讨论】:

      猜你喜欢
      • 2022-08-24
      • 1970-01-01
      • 2022-08-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-09
      • 2018-09-04
      相关资源
      最近更新 更多