Skip to content
Open
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
11 changes: 11 additions & 0 deletions docs/avatar-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,17 @@ expanded Example drawing, the avatar and its button are hidden rather than
allowed to cover code or the drawing, and the captions move to the bottom
corner.

The same measurement tells the editor what the stage covers, and the editor
keeps it out of its scroll range: the end of a long line and the caret typing
there come to rest beside the floating stage, and the last rows scroll above
the compact card, while a click beside the code still reaches the editor. The
width beside the floating stage is reserved once for the whole editor, so rows
below the stage end at the same column and leave an empty strip under it; that
strip is the reservation, not a layout gap. Code still passes under the compact
card before it is scrolled. An editor that runs past the window, as under the
stacked sidebar on a narrow screen, reserves nothing, since the page itself
scrolls any row out from under the card.

Every VRM loads in a T-pose and the format ships no idle animation, so
`loadVrm` drops the upper arms once at load. This is model-independent: without
it any model stands in frame with its arms straight out. It does not help a
Expand Down
126 changes: 126 additions & 0 deletions tests/browser/interview-layout.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,132 @@ test("a narrow window and a narrow panel both make the stage compact", async (t)
}
});

/// Says where the last character of the buffer is painted, where the stage and
/// the editor stack are, and how far each editor layer has scrolled.
const measure = (page) =>
page.evaluate(() => {
const [editor, layer, lines, stage] = [
"#editor",
"#editor-highlight",
"#editor-lines",
"#jim-stage",
].map((selector) => document.querySelector(selector));
const walker = document.createTreeWalker(layer, NodeFilter.SHOW_TEXT);
let last = null;
for (let node = walker.nextNode(); node; node = walker.nextNode())
if (node.data.trim()) last = node;
const end = last.data.trimEnd().length;
const glyph = document.createRange();
glyph.setStart(last, end - 1);
glyph.setEnd(last, end);
return {
glyph: glyph.getBoundingClientRect().toJSON(),
stage: stage.getBoundingClientRect().toJSON(),
editor: editor.parentElement.getBoundingClientRect().toJSON(),
compact: stage.classList.contains("compact"),
drift: [
layer.scrollLeft - editor.scrollLeft,
layer.scrollTop - editor.scrollTop,
lines.scrollTop - editor.scrollTop,
],
};
});

/// Types `text` over the buffer, so the caret ends after it, and measures.
async function typeToEnd(page, text) {
await page
.locator("#editor")
.evaluate((node) => node.setSelectionRange(0, node.value.length));
await page.locator("#editor").focus();
await page.keyboard.insertText(text);
await settled(page);
return measure(page);
}

// Floating beside the code at the two wide windows, the compact card at 1100,
// where the line is the last row so it starts under the card. There the
// smallest test drawer puts more of the editor under the card than it would
// otherwise cover, after the reserve was first measured.
for (const [width, height, rows] of [
[1920, 1080, 2],
[1366, 900, 2],
[1100, 800, 80],
]) {
test(`at ${width}px the caret at the end of a long line scrolls clear of Jim's stage`, async (t) => {
if (!browser) return t.skip("playwright chromium unavailable");
const page = await openInterview(width, height);
try {
await closeSetupCheck(page);
if (width < 1200) {
await page.focus("#test-drawer-resizer");
await page.keyboard.press("Home");
}
const above = Array.from({ length: rows }, (_, row) => `# row ${row}`);
await typeToEnd(
page,
[...above, `# ${"0123456789".repeat(30)}`].join("\n"),
);
await page.keyboard.press("Home");
await settled(page);
const start = await measure(page);
assert.ok(
start.glyph.right > start.editor.right,
"the line is longer than the editor",
);
assert.ok(
start.stage.left < start.editor.right &&
start.stage.top < start.editor.bottom,
"the stage covers the editor, or this proves nothing",
);
await page.keyboard.press("End");
await settled(page);
const { glyph, stage, compact, drift } = await measure(page);
assert.equal(compact, width < 1200, "the stage this width shows");
if (compact)
assert.ok(
glyph.bottom <= stage.top,
`the last row ends at ${glyph.bottom}, under the card from ${stage.top}`,
);
else
assert.ok(
glyph.right <= stage.left,
`the line ends at ${glyph.right}, under the stage from ${stage.left}`,
);
// The textarea holds the caret; the overlay and the gutter must have
// scrolled exactly as far, or the painted end is not where the caret is.
assert.deepEqual(drift, [0, 0, 0]);
} finally {
await page.close();
}
});
}

test("a click beside the code below Jim's floating stage stays in the editor", async (t) => {
if (!browser) return t.skip("playwright chromium unavailable");
const page = await openInterview(1366, 900);
try {
await closeSetupCheck(page);
const rows = Array.from({ length: 30 }, (_, row) => `x${row} = ${row}`);
const seen = await typeToEnd(page, rows.join("\n"));
await page
.locator("#editor")
.evaluate((node) => node.setSelectionRange(0, 0));
// Right of the short rows, in the strip the stage reserves, under it.
const x = Math.round((seen.stage.left + seen.editor.right) / 2);
const y = Math.round(seen.stage.bottom + 60);
assert.ok(y < seen.editor.bottom, "the click lands on a row of code");
await page.mouse.click(x, y);
const after = await page.evaluate(() => ({
focused: document.activeElement?.id,
caret: document.querySelector("#editor").selectionStart,
}));
assert.equal(after.focused, "editor", "the click keeps the editor focused");
assert.ok(after.caret > 0, "the click moves the caret to that row");
} finally {
await page.close();
}
});

test("the report is a modal dialog with one primary action", async (t) => {
if (!browser) return t.skip("playwright chromium unavailable");
const page = await openInterview(1280, 800);
Expand Down
33 changes: 33 additions & 0 deletions web/interview.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,9 @@ const JIM_SELF_VIEW_WIDTH_PX = 120;

/// In px, between the editor toolbar's bottom and the top of Jim's stage.
const JIM_STAGE_TOOLBAR_GAP_PX = 6;
/// In px, between the end of the editor's text and the floating stage, so the
/// last glyph never ends flush against it or a fraction under it.
const JIM_STAGE_EDITOR_GAP_PX = 6;

// From /runtime-config.js, which is the only thing allowed to name what the
// server does. A literal here would be a second answer to "does this server
Expand Down Expand Up @@ -5857,14 +5860,44 @@ function placeJimStageBelowToolbar(toolbar) {
"scrollable",
stage.top < 0 || stage.bottom > window.innerHeight,
);
reserveJimStageInEditor(stage);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The reservation uses a stale stage rectangle after .scrollable can reposition the stage. Re-read getBoundingClientRect() after toggling .scrollable, otherwise an oversized compact card can reserve the fixed-bottom position while it is actually rendered at the toolbar anchor.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At web/interview.js, line 5863:

<comment>The reservation uses a stale stage rectangle after `.scrollable` can reposition the stage. Re-read `getBoundingClientRect()` after toggling `.scrollable`, otherwise an oversized compact card can reserve the fixed-bottom position while it is actually rendered at the toolbar anchor.</comment>

<file context>
@@ -5857,14 +5860,44 @@ function placeJimStageBelowToolbar(toolbar) {
       "scrollable",
       stage.top < 0 || stage.bottom > window.innerHeight,
     );
+    reserveJimStageInEditor(stage);
   };
   const observer = new window.ResizeObserver(place);
</file context>
Suggested change
reserveJimStageInEditor(stage);
reserveJimStageInEditor(nodes.jimStage.getBoundingClientRect());

};
const observer = new window.ResizeObserver(place);
observer.observe(toolbar);
observer.observe(nodes.jimStage);
// The test drawer's splitter moves the editor's bottom under the card.
if (nodes.editorStack.isConnected) observer.observe(nodes.editorStack);
window.addEventListener("resize", place);
place();
}

/// Tells the editor how much of it Jim's stage covers, so the end of a long
/// line and the caret never scroll under it: the right edge beside the floating
/// stage, the bottom under the compact card. A whiteboard has no editor, and an
/// editor running past the window scrolls with the page, which already brings
/// any row out from under the fixed card.
function reserveJimStageInEditor(stage) {
const stack = nodes.editorStack;
if (!stack.isConnected) return;
const editor = stack.getBoundingClientRect();
const covers =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: The reservation is computed from viewport positions, but it only refreshes on resize, not on scroll. When the editor panel or page scrolls, covers can flip while --jim-stage-reserve-right and --jim-stage-reserve-bottom keep their old values, so the caret can sit under the stage. Re-run the reservation on scroll of the editor panel, or compute it without depending on the viewport position.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At web/interview.js, line 5883:

<comment>The reservation is computed from viewport positions, but it only refreshes on resize, not on scroll. When the editor panel or page scrolls, `covers` can flip while `--jim-stage-reserve-right` and `--jim-stage-reserve-bottom` keep their old values, so the caret can sit under the stage. Re-run the reservation on scroll of the editor panel, or compute it without depending on the viewport position.</comment>

<file context>
@@ -5857,14 +5860,44 @@ function placeJimStageBelowToolbar(toolbar) {
+  const stack = nodes.editorStack;
+  if (!stack.isConnected) return;
+  const editor = stack.getBoundingClientRect();
+  const covers =
+    editor.top >= 0 &&
+    editor.bottom <= window.innerHeight &&
</file context>

editor.top >= 0 &&
editor.bottom <= window.innerHeight &&
stage.width > 0 &&
stage.left < editor.right &&
stage.right > editor.left &&
stage.top < editor.bottom &&
stage.bottom > editor.top;
const compact = nodes.jimStage.classList.contains("compact");
const right =
covers && !compact
? Math.ceil(editor.right - stage.left) + JIM_STAGE_EDITOR_GAP_PX
: 0;
const bottom = covers && compact ? Math.ceil(editor.bottom - stage.top) : 0;
stack.style.setProperty("--jim-stage-reserve-right", `${right}px`);
stack.style.setProperty("--jim-stage-reserve-bottom", `${bottom}px`);
}

function editorFontSize() {
return nodes.editorStack.style
.getPropertyValue("--editor-font-size")
Expand Down
11 changes: 11 additions & 0 deletions web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -1639,8 +1639,15 @@ p {
position: absolute;
inset: 0 0 0 var(--editor-gutter);
margin: 0;
/* What Jim's stage covers, measured by interview.js. A border, not right
padding, which a textarea leaves out of its scroll range, nor a narrower
box, which would not take a click beside the code. The compact card,
which grows with the captions, gets bottom padding so the text area
never resizes while Jim speaks. */
border: 0;
border-right: var(--jim-stage-reserve-right, 0px) solid transparent;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In forced-colors mode (Windows High Contrast) the browser replaces transparent here with the forced border color, so the reservation paints as a solid CanvasText bar, about 180px wide at 1366x900, down the whole right side of #editor and #editor-highlight, including the strip below Jim's stage that the contract now describes as empty. Headless Chromium with forcedColors: "active" computes this border as rgb(0, 0, 0) on both a textarea and a pre and paints it black, and no @media (forced-colors: active) rule in web/styles.css covers these layers. The editor needs a forced-colors rule for this border; forced-color-adjust: none with border-right-color: Canvas keeps the strip blank there, but it also opts the text out, so color and the syntax token colors would then have to use system colors in that rule too.

padding: 1rem;
padding-bottom: calc(1rem + var(--jim-stage-reserve-bottom, 0px));
font-family: var(--editor-font-family);
font-size: var(--editor-font-size);
line-height: 1.5;
Expand Down Expand Up @@ -1695,6 +1702,8 @@ p {
width: var(--editor-gutter);
margin: 0;
padding: 1rem 0.5rem;
/* Follows the text layers' scrollTop, so it reserves the same bottom. */
padding-bottom: calc(1rem + var(--jim-stage-reserve-bottom, 0px));
overflow: hidden;
color: var(--code-gutter-ink);
background-color: var(--code-gutter);
Expand All @@ -1715,6 +1724,8 @@ p {
past what they can follow and the painted text would sit a line above the
caret near the end of a long file. Wheel, keys, and the caret still scroll. */
scrollbar-width: none;
/* Keeps the caret above the compact card while typing. */
scroll-padding-bottom: calc(1rem + var(--jim-stage-reserve-bottom, 0px));
background: transparent;
/* Transparent glyphs: the overlay supplies the visible, colored ones. */
color: transparent;
Expand Down