Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
C-Loftus authored Mar 17, 2024
2 parents 5c801d3 + b01b553 commit a6f9ee9
Show file tree
Hide file tree
Showing 5 changed files with 574 additions and 539 deletions.
10 changes: 8 additions & 2 deletions docs/contributing/adding-a-new-package.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,16 @@ Replace `foo` with your new package name in the instructions below.
1. `cd packages`
2. `mkdir foo && cd foo`
3. `pnpm init`
4. `code package.json` and update the `description` field
4. `code package.json` and update the `description` field. If your package is
not a library (ie it's an entrypoint), add a `"private": true,` line to your
`package.json`.
5. `pnpm install`
6. `pnpm -w fix:meta`
7. If your package is not a library (ie it's an entrypoint), add a `"private": true,` line to your `package.json`, then run another `pnpm -w fix:meta` for good measure.

If your package is not a library, you get a bit less scaffolding for free, so
you may want to steal some of the scripts, as well as possibly the `main`,
`types`, and `exports` fields, from one of our library's `package.json`s. The
`@cursorless/common` package is a decent one to steal from.

For any packages that you need to depend on, you can run

Expand Down
12 changes: 12 additions & 0 deletions packages/cursorless-vscode/resources/font_measurements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const letter = document.querySelector("#letter");
const container = document.querySelector("#container");
const baselineHeight =
letter.offsetTop +
letter.offsetHeight -
container.offsetHeight -
container.offsetTop;
const vscode = acquireVsCodeApi();
vscode.postMessage({
widthRatio: letter.offsetWidth / 1000,
heightRatio: (letter.offsetHeight - baselineHeight) / 1000,
});
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class FontMeasurementsImpl implements FontMeasurements {
}>("fontRatios");

if (fontRatiosCache == null || fontRatiosCache.fontFamily !== fontFamily) {
const fontRatios = await getFontRatios();
const fontRatios = await getFontRatios(this.extensionContext);
this.extensionContext.globalState.update("fontRatios", {
...fontRatios,
fontFamily,
Expand All @@ -57,7 +57,7 @@ export class FontMeasurementsImpl implements FontMeasurements {
*
* @returns The width and height ratios of the font
*/
function getFontRatios() {
function getFontRatios(extensionContext: vscode.ExtensionContext) {
const panel = vscode.window.createWebviewPanel(
"cursorless.loading",
"Cursorless",
Expand All @@ -70,7 +70,14 @@ function getFontRatios() {
},
);

panel.webview.html = getWebviewContent();
const font_measurement_js = panel.webview.asWebviewUri(
vscode.Uri.joinPath(
extensionContext.extensionUri,
"resources",
"font_measurements.js",
),
);
panel.webview.html = getWebviewContent(panel.webview, font_measurement_js);

interface FontRatios {
/**
Expand Down Expand Up @@ -103,25 +110,23 @@ function getFontFamily() {
return config.get<string>("fontFamily")!;
}

function getWebviewContent() {
function getWebviewContent(
webview: vscode.Webview,
font_measurement_js: vscode.Uri,
) {
// baseline adjustment based on https://stackoverflow.com/a/27295528
return `<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Security-Policy" content="script-src ${webview.cspSource};" />
</head>
<body>
<h1>Loading Cursorless...</h1>
<div id="container">
<span id="letter" style="line-height: 0; visibility:hidden; font-size: 1000px; font-family: var(--vscode-editor-font-family); font-weight: var(--vscode-editor-font-weight);">A</span>
</div>
<script>
const letter = document.querySelector('#letter');
const container = document.querySelector('#container');
const baselineHeight = letter.offsetTop + letter.offsetHeight - container.offsetHeight - container.offsetTop;
const vscode = acquireVsCodeApi();
vscode.postMessage({
widthRatio: letter.offsetWidth / 1000,
heightRatio: (letter.offsetHeight - baselineHeight) / 1000
});
</script>
<script src="${font_measurement_js}"></script>
</body>
</html>`;
}
4 changes: 4 additions & 0 deletions packages/cursorless-vscode/src/scripts/populateDist/assets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export const assets: Asset[] = [
{ source: "../../images/hats", destination: "images/hats" },
{ source: "./images/logo.png", destination: "images/logo.png" },
{ source: "../../images/logo.svg", destination: "images/logo.svg" },
{
source: "resources/font_measurements.js",
destination: "resources/font_measurements.js",
},
{ source: "../../schemas", destination: "schemas" },
{
source: "../../third-party-licenses.csv",
Expand Down
Loading

0 comments on commit a6f9ee9

Please sign in to comment.