diff --git a/docs/avatar-contract.md b/docs/avatar-contract.md index bf5fa9ed3..b5fefd17c 100644 --- a/docs/avatar-contract.md +++ b/docs/avatar-contract.md @@ -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 diff --git a/tests/browser/interview-layout.test.js b/tests/browser/interview-layout.test.js index 53b7d36ea..700fb0fb2 100644 --- a/tests/browser/interview-layout.test.js +++ b/tests/browser/interview-layout.test.js @@ -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); diff --git a/web/interview.js b/web/interview.js index 3f37cee40..51ccbc13f 100644 --- a/web/interview.js +++ b/web/interview.js @@ -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 @@ -5857,14 +5860,44 @@ function placeJimStageBelowToolbar(toolbar) { "scrollable", stage.top < 0 || stage.bottom > window.innerHeight, ); + reserveJimStageInEditor(stage); }; 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 = + 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") diff --git a/web/styles.css b/web/styles.css index 6a07737e0..3458712e5 100644 --- a/web/styles.css +++ b/web/styles.css @@ -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; 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; @@ -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); @@ -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;