从摩纳哥编辑器实例获取fontInfo?

时间:2020-08-27 22:50:20

标签: monaco-editor

我正在尝试获取typicalFullwidthCharacterWidth的{​​{1}}类中可用的FontInfo属性。

如摩纳哥编辑文档中所示:

monaco.editor documentation

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

查看使用monaco.editor的Minimap组件:

monaco-editor minimap component

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

是否可以公开获取?

1 个答案:

答案 0 :(得分:0)

我已经找到了解决方案,您必须使用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", …}