从 monaco-editor 实例获取 fontInfo?

Getting fontInfo from monaco-editor instance?

我正在尝试获取 typicalFullwidthCharacterWidth 属性 monaco.editor class 中可用的 monaco.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

是否可以将其公开?

我找到了解决办法,你必须使用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", …}