Skip to content

Commit 3219b99

Browse files
committed
fix(es-app): the Front desk editor never expands on its own; it grows by wrapped lines and shrinks back (Main1690, anomalyco#232)
1 parent 5445167 commit 3219b99

2 files changed

Lines changed: 125 additions & 0 deletions

File tree

‎packages/es-app/src/pages/session.tsx‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,9 @@ export function SessionView(props: { sessionID: string; directory: string; embed
14551455
const box = el.clientHeight
14561456
// A hidden draft (a pending-input edit is open) has no box to fill.
14571457
if (!box) return false
1458+
// A content-sized editor (the Front desk) grows with its wrapped lines to its own max-height and then scrolls
1459+
// inside; its box always equals its content, so it is never "nearly full" and never expands on its own.
1460+
if (getComputedStyle(el).getPropertyValue("field-sizing") === "content") return false
14581461
if (el.scrollHeight > box) return true
14591462
const style = [el.style.height, el.style.minHeight, el.style.transition] as const
14601463
const top = el.scrollTop
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
// Main1690 / Desk2329 (#232): in the Front desk companion, a manually expanded editor keeps its height while typing
2+
// (continuous non-wrapping and wrapping text, deleting back, a multi-line paste, undo); the content-sized auto mode
3+
// never expands on its own: it grows by wrapped lines to its max-height, then scrolls, and shrinks on delete. Records the textarea height and expanded state at every animation frame and
4+
// after every key, and fails on any height change that is not a line-step in auto mode or any change at all in
5+
// manual expanded mode. Synthetic draft in a disposable fixture; no sends.
6+
// Run from packages/es-app: node test/desk-expand-typing.browser.mjs
7+
import assert from "node:assert/strict"
8+
import { createRequire } from "node:module"
9+
import { startPanelPreview } from "./composer-panel-preview.mjs"
10+
import { directory } from "./composer-fixture.mjs"
11+
12+
const { chromium, expect } = createRequire(new URL("../../app/package.json", import.meta.url))("@playwright/test")
13+
const preview = await startPanelPreview()
14+
preview.fixture.status = "idle"
15+
const browser = await chromium.launch({ channel: "chrome", headless: true })
16+
const viewport = { width: Number(process.env.VW ?? 1440), height: Number(process.env.VH ?? 900) }
17+
const context = await browser.newContext({ viewport })
18+
await context.route("**/*", route => new URL(route.request().url()).origin === preview.origin ? route.continue() : route.abort())
19+
await context.addInitScript(value => { try { localStorage.setItem("es-app:front-desk:1", JSON.stringify(value)); localStorage.setItem("es-app:companion:work", "1") } catch {} }, { session: "ses_b", directory })
20+
const page = await context.newPage()
21+
page.setDefaultTimeout(60_000)
22+
const errors = []
23+
page.on("pageerror", error => errors.push(error.message))
24+
const failures = []
25+
try {
26+
await page.goto(`${preview.origin}/agents`, { waitUntil: "domcontentloaded", timeout: 300_000 })
27+
const companion = page.locator(".desk-companion")
28+
const editor = companion.locator(".direct-composer textarea[aria-label='Message']")
29+
await expect(editor).toBeVisible({ timeout: 120_000 })
30+
// Frame sampler: every distinct (height, expanded) pair, in order.
31+
await editor.evaluate(el => {
32+
const box = el.closest(".prompt-box")
33+
window.__trace = []
34+
const tick = () => {
35+
const h = Math.round(el.getBoundingClientRect().height)
36+
const expanded = box.classList.contains("prompt-expanded")
37+
const last = window.__trace.at(-1)
38+
if (!last || last.h !== h || last.expanded !== expanded) window.__trace.push({ t: Math.round(performance.now()), h, expanded, len: el.value.length })
39+
window.__raf = requestAnimationFrame(tick)
40+
}
41+
tick()
42+
})
43+
const trace = () => page.evaluate(() => window.__trace)
44+
// Keeps the current sample as the baseline, so a trace lists only changes after it.
45+
const reset = () => page.evaluate(() => { window.__trace = window.__trace.slice(-1) })
46+
const settle = () => page.waitForTimeout(350)
47+
const lineHeight = await editor.evaluate(el => parseFloat(getComputedStyle(el).lineHeight) || 20)
48+
const instance = await editor.evaluate(el => { el.dataset.instance = "one"; return true })
49+
50+
// Manual expanded mode.
51+
await editor.focus()
52+
await companion.getByRole("button", { name: /^Expand editor/ }).click()
53+
await expect(companion.locator(".prompt-box")).toHaveClass(/prompt-expanded/)
54+
await editor.focus()
55+
await settle()
56+
await reset()
57+
const steps = [
58+
["non-wrapping", async () => { for (const ch of "hello there") await page.keyboard.type(ch) }],
59+
["wrapping", async () => { for (const ch of " word".repeat(60)) await page.keyboard.type(ch) }],
60+
["deleting", async () => { for (let i = 0; i < 200; i++) await page.keyboard.press("Backspace") }],
61+
["paste multi-line", async () => { await editor.evaluate(el => { const data = new DataTransfer(); data.setData("text/plain", "a\nb\nc\nd\ne\nf"); el.dispatchEvent(new ClipboardEvent("paste", { clipboardData: data, bubbles: true, cancelable: true })) }); await page.keyboard.insertText("a\nb\nc\nd\ne\nf") }],
62+
["undo", async () => { await page.keyboard.press("ControlOrMeta+z") }],
63+
]
64+
for (const [name, act] of steps) {
65+
await act()
66+
await settle()
67+
const rows = await trace()
68+
const heights = [...new Set(rows.map(row => row.h))]
69+
const collapsed = rows.some(row => !row.expanded)
70+
if (heights.length > 1 || collapsed) failures.push({ mode: "manual expanded", step: name, heights, collapsed, changes: rows.length })
71+
await reset()
72+
}
73+
await expect(editor).toHaveAttribute("data-instance", "one")
74+
75+
// Auto mode (collapse, clear): height may change only in whole-line steps, never back and forth per key.
76+
await companion.getByRole("button", { name: /^Collapse editor/ }).click()
77+
await editor.fill("")
78+
await editor.focus()
79+
await settle()
80+
await reset()
81+
for (const ch of "short") await page.keyboard.type(ch)
82+
await settle()
83+
let rows = await trace()
84+
if (rows.length > 1) failures.push({ mode: "auto", step: "typing a short line", heights: rows.map(row => row.h), expanded: rows.map(row => row.expanded) })
85+
const oneLine = await editor.evaluate(el => Math.round(el.getBoundingClientRect().height))
86+
await reset()
87+
for (const ch of " word".repeat(40)) await page.keyboard.type(ch)
88+
await settle()
89+
rows = await trace()
90+
const flips = rows.filter((row, index) => index && row.h < rows[index - 1].h).length
91+
if (flips) failures.push({ mode: "auto", step: "wrapping", note: "height went down while typing", heights: rows.map(row => row.h), expanded: rows.map(row => row.expanded) })
92+
93+
// Auto mode never enters expanded mode; growth stays within its own max-height.
94+
if (rows.some(row => row.expanded)) failures.push({ mode: "auto", step: "wrapping", note: "expanded on its own" })
95+
const max = await editor.evaluate(el => parseFloat(getComputedStyle(el).maxHeight))
96+
if (rows.some(row => row.h > max + 1)) failures.push({ mode: "auto", step: "wrapping", note: `taller than its max-height ${max}` })
97+
// Keep typing and deleting: it must not flip between modes per key.
98+
await reset()
99+
for (const ch of " more".repeat(30)) await page.keyboard.type(ch)
100+
for (let i = 0; i < 60; i++) await page.keyboard.press("Backspace")
101+
await settle()
102+
rows = await trace()
103+
const modeFlips = rows.filter((row, index) => index && row.expanded !== rows[index - 1].expanded).length
104+
if (modeFlips) failures.push({ mode: "auto", step: "typing after auto-expand", note: "expanded/collapsed flips", flips: modeFlips, heights: rows.map(row => row.h).slice(0, 40) })
105+
106+
// Deleting back to one line shrinks it to its starting height.
107+
await editor.fill("")
108+
await editor.focus()
109+
for (const ch of "short") await page.keyboard.type(ch)
110+
await settle()
111+
const back = await editor.evaluate(el => Math.round(el.getBoundingClientRect().height))
112+
if (back !== oneLine) failures.push({ mode: "auto", step: "shrink on delete", note: `${back} != ${oneLine}` })
113+
await expect(editor).toHaveAttribute("data-instance", "one")
114+
115+
console.log(JSON.stringify({ viewport, lineHeight, failures }, null, 1))
116+
assert.deepEqual(failures, [], "editor height changed outside intended line steps")
117+
assert.deepEqual(errors, [])
118+
console.log("PASS desk editor: manual expanded height stable through typing, wrapping, deleting, paste and undo; auto never expands on its own, grows by lines within max-height, shrinks back; same textarea")
119+
} finally {
120+
await browser.close()
121+
await preview.close()
122+
}

0 commit comments

Comments
 (0)