Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions tests/browser/editor-pipeline.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// A browser-level pin for the bracket auto-close pipeline in web/editor.js
// and web/interview.js.
// A browser-level pin for the editor pipeline in web/editor.js and
// web/interview.js: bracket auto-close, and the overlay that paints its text.
import { after, before, test } from "node:test";
import assert from "node:assert/strict";

Expand Down Expand Up @@ -154,3 +154,29 @@ test("Backspace right after an auto-closed pair removes both characters, in a re
await page.close();
}
});

test("the highlight overlay resolves the textarea's font metrics, in a real browser", async (t) => {
const ctx = await editorPage(t);
if (!ctx) return;
const { page } = ctx;
try {
// The overlay paints the glyphs the textarea positions. Any metric of the
// shared #editor, #editor-highlight rule that <code> resolves on its own
// moves the painted text away from the caret, a little more every line.
const [editor, overlay] = await page.evaluate(() =>
["#editor", "#editor-highlight code"].map((selector) => {
const style = getComputedStyle(document.querySelector(selector));
return {
fontFamily: style.fontFamily,
fontSize: style.fontSize,
lineHeight: style.lineHeight,
fontWeight: style.fontWeight,
letterSpacing: style.letterSpacing,
};
}),
);
assert.deepEqual(overlay, editor);
} finally {
await page.close();
}
});
7 changes: 7 additions & 0 deletions web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -899,6 +899,13 @@ p {
overflow: hidden;
}

/* The user-agent stylesheet gives <code> its own monospace family, which
beats the inherited stack and paints the overlay in a different font from
the textarea, so the text drifts from the caret line by line. */
#editor-highlight code {
font: inherit;
}

#editor-lines {
position: absolute;
inset: 0 auto 0 0;
Expand Down