* Rapidly shows a webview in order to measure the width and height of a character in the users font * * @returns The width and height ratios of the font
()
| 58 | * @returns The width and height ratios of the font |
| 59 | */ |
| 60 | function getFontRatios() { |
| 61 | const panel = vscode.window.createWebviewPanel( |
| 62 | "cursorless.loading", |
| 63 | "Cursorless", |
| 64 | { |
| 65 | preserveFocus: true, |
| 66 | viewColumn: vscode.ViewColumn.Active, |
| 67 | }, |
| 68 | { |
| 69 | enableScripts: true, |
| 70 | } |
| 71 | ); |
| 72 | |
| 73 | panel.webview.html = getWebviewContent(); |
| 74 | |
| 75 | interface FontRatios { |
| 76 | /** |
| 77 | * The ratio of the width of a character in the given font to the font size |
| 78 | */ |
| 79 | widthRatio: number; |
| 80 | |
| 81 | /** |
| 82 | * The ratio of the height of a character in the given font to the font |
| 83 | * size. The height is measured from the baseline to the top of the span |
| 84 | */ |
| 85 | heightRatio: number; |
| 86 | } |
| 87 | |
| 88 | return new Promise<FontRatios>((resolve) => { |
| 89 | panel.webview.onDidReceiveMessage((message) => { |
| 90 | panel.dispose(); |
| 91 | resolve(message); |
| 92 | }); |
| 93 | }); |
| 94 | } |
| 95 | |
| 96 | function getFontSize() { |
| 97 | const config = vscode.workspace.getConfiguration("editor"); |
no test coverage detected