fix(mobile): the phone toolbar sits on the keyboard, and the prompt's last line is no longer under it

With the on-screen keyboard up, the toolbar and the keyboard accessory bar
kept a bottom offset of --safe-area-bottom (34px on a Face ID iPhone, since
the page sets viewport-fit=cover), although the keyboard covers the
home-indicator strip that inset reserves. That left an empty band between
the toolbar and the keyboard, and put the bars 34px above the room main's
keyboard padding reserves for them (84px, the two bars only), so the bottom
of the terminal box, the last line of the prompt being typed, was painted
under the accessory bar.

With the keyboard up the bars now stack from 0 (toolbar), 40px (accessory
bar) and 84px (CJK textarea), on iOS Safari and in the home-screen app alike.
Nothing changes with the keyboard down, on a tablet or on desktop.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Codeman maintainer committed 2026-11-15 14:00:34 +01:00
1 parent e99b42c387
commit e4a85fabcd
3 files changed
+176 -6

No files matched your search

+120
View File
@@ -0,0 +1,120 @@
/**
* @fileoverview With the on-screen keyboard up, the phone's toolbar and keyboard
* accessory bar sit DIRECTLY on the keyboard, with no bottom safe-area gap.
*
* Both bars are `position: fixed` and `KeyboardHandler.updateLayoutForKeyboard()`
* lifts them by the whole distance from the layout-viewport bottom to the
* visual-viewport bottom, i.e. onto the keyboard's top edge. Their CSS `bottom`
* still added `--safe-area-bottom` (env(safe-area-inset-bottom), 34px on a Face ID
* iPhone because index.html sets `viewport-fit=cover`), although the keyboard
* covers the home-indicator strip that inset reserves. Two things followed, both
* seen on an iPhone:
*
* 1. an empty 34px band between the toolbar and the keyboard;
* 2. the bars stood 34px ABOVE the room `main`'s keyboard padding reserves for
* them. That padding (84px, set inline by KeyboardHandler) counts the two
* bars only, so the bottom 34px of the terminal box, the last line of the
* prompt being typed, was painted under the accessory bar.
*
* So the keyboard-up offsets must be the bar stack alone: toolbar at 0, the
* accessory bar on the toolbar, the CJK textarea on the accessory bar, and the
* top of that stack equal to the padding the JS reserves.
*
* Parsed with postcss: headless Chromium reports a zero safe area, so the browser
* suite cannot show the gap, and that suite is not part of the CI gate anyway.
* Port: N/A.
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import postcss, { type AtRule, type Root, type Rule } from 'postcss';
import { describe, expect, it } from 'vitest';
const PUBLIC = resolve(import.meta.dirname, '../src/web/public');
const MOBILE = postcss.parse(readFileSync(resolve(PUBLIC, 'mobile.css'), 'utf8'));
const STYLES = postcss.parse(readFileSync(resolve(PUBLIC, 'styles.css'), 'utf8'));
const HANDLERS = readFileSync(resolve(PUBLIC, 'mobile-handlers.js'), 'utf8');
/** The phone breakpoint block of mobile.css (the toolbar is fixed only there). */
function phoneBlock(): AtRule {
let found: AtRule | undefined;
MOBILE.walkAtRules('media', (at) => {
if (!found && at.params.trim() === '(max-width: 599px)' && at.parent?.type === 'root') found = at;
});
if (!found) throw new Error('mobile.css has no top-level (max-width: 599px) block');
return found;
}
/** The last value `prop` gets from a rule whose selector list contains `selector`. */
function lastDecl(root: Root | AtRule, selector: string, prop: string): string | undefined {
let value: string | undefined;
root.walkRules((rule: Rule) => {
if (!rule.selectors.includes(selector)) return;
// Only the block's own rules: a nested @media inside it applies to a narrower width.
if (rule.parent !== root) return;
rule.walkDecls(prop, (d) => {
value = d.value;
});
});
return value;
}
const PHONE = phoneBlock();
describe('phone bars with the keyboard up', () => {
// Every selector that sets a keyboard-up `bottom` on these bars, generic and
// iOS Safari (which needs its own, to outrank `.ios-device.safari-browser .toolbar`).
const toolbarSelectors = ['.keyboard-visible .toolbar', '.keyboard-visible.ios-device.safari-browser .toolbar'];
const accessorySelectors = [
'.keyboard-visible .keyboard-accessory-bar',
'.keyboard-visible.ios-device.safari-browser .keyboard-accessory-bar',
];
it('reserve no bottom safe area (the keyboard covers the home indicator)', () => {
for (const selector of [...toolbarSelectors, ...accessorySelectors]) {
const bottom = lastDecl(PHONE, selector, 'bottom');
expect(bottom, selector).toBeDefined();
expect(bottom, selector).not.toMatch(/safe-area|chrome-overlap/);
}
const cjk = lastDecl(PHONE, '.touch-device.keyboard-visible #cjkInput.cjk-input-visible', 'bottom');
expect(cjk).toBeDefined();
expect(cjk).not.toMatch(/safe-area/);
});
it('stack toolbar, accessory bar and CJK textarea with no gaps between them', () => {
const px = (v: string | undefined) => {
expect(v).toMatch(/^\d+(px)?$/);
return parseFloat(v as string);
};
const toolbarHeight = px(lastDecl(PHONE, '.toolbar', 'height'));
const accessoryHeight = px(lastDecl(PHONE, '.keyboard-accessory-bar', 'height'));
for (const selector of toolbarSelectors) expect(px(lastDecl(PHONE, selector, 'bottom')), selector).toBe(0);
for (const selector of accessorySelectors) {
expect(px(lastDecl(PHONE, selector, 'bottom')), selector).toBe(toolbarHeight);
}
expect(px(lastDecl(PHONE, '.touch-device.keyboard-visible #cjkInput.cjk-input-visible', 'bottom'))).toBe(
toolbarHeight + accessoryHeight
);
});
it("put the stack's top exactly where main's keyboard padding ends", () => {
// KeyboardHandler.updateLayoutForKeyboard(): `${84 + cjkInputHeight}px`.
const match = HANDLERS.match(/main\.style\.paddingBottom = `\$\{(\d+) \+ cjkInputHeight\}px`/);
expect(match, 'the keyboard padding assignment in mobile-handlers.js').not.toBeNull();
const reserved = Number(match![1]);
const toolbarHeight = parseFloat(lastDecl(PHONE, '.toolbar', 'height') ?? 'NaN');
const accessoryHeight = parseFloat(lastDecl(PHONE, '.keyboard-accessory-bar', 'height') ?? 'NaN');
expect(reserved).toBe(toolbarHeight + accessoryHeight);
});
it('beat the touch-device CJK rule in styles.css, which still adds the safe area', () => {
// Same selector in both files: mobile.css loads after styles.css, so its rule
// wins on a phone. If styles.css ever drops the safe area this test can go.
expect(lastDecl(STYLES, '.touch-device.keyboard-visible #cjkInput.cjk-input-visible', 'bottom')).toMatch(
/safe-area-bottom/
);
const html = readFileSync(resolve(PUBLIC, 'index.html'), 'utf8');
expect(html.indexOf('href="styles.css"')).toBeGreaterThan(-1);
expect(html.indexOf('href="mobile.css"')).toBeGreaterThan(html.indexOf('href="styles.css"'));
});
});
+35
View File
@@ -163,6 +163,41 @@ describe('Virtual Keyboard', () => {
}
});
it('sits the bars on the keyboard with no safe-area band, and no terminal under them', async () => {
// The mock layer is the faithful iOS model: the layout viewport keeps its
// height and only the visual viewport shrinks, so KeyboardHandler lifts the
// fixed bars by translateY. Headless Chromium has no home indicator, so the
// 34px inset a Face ID iPhone reports under viewport-fit=cover is forced.
const { context, page } = await createDevicePage(device, 'about:blank', 'chromium');
try {
await setupViewportMock(page);
await page.goto(baseUrl, { waitUntil: WAIT.DOM_CONTENT_LOADED });
await page.waitForTimeout(2000);
await page.evaluate(() => document.documentElement.style.setProperty('--safe-area-bottom', '34px'));
expect(await showKeyboardViaMock(page, KEYBOARD.TYPICAL_IOS_HEIGHT)).toBe(true);
await page.waitForTimeout(WAIT.KEYBOARD_ANIMATION);
const layout = await page.evaluate(() => {
const rect = (sel: string) => (document.querySelector(sel) as HTMLElement | null)?.getBoundingClientRect();
return {
visualBottom: (window.visualViewport?.offsetTop ?? 0) + (window.visualViewport?.height ?? 0),
toolbar: rect('.toolbar'),
accessory: rect('.keyboard-accessory-bar'),
terminal: rect('#terminalContainer'),
};
});
// Flush on the keyboard: the old CSS left the toolbar 34px above it.
expect(Math.abs(layout.toolbar!.bottom - layout.visualBottom)).toBeLessThanOrEqual(1);
expect(Math.abs(layout.accessory!.bottom - layout.toolbar!.top)).toBeLessThanOrEqual(1);
// The terminal's box ends where the bars begin, so its last row (the end of
// the prompt being typed) is not painted under the accessory bar.
expect(layout.terminal!.bottom).toBeLessThanOrEqual(layout.accessory!.top + 1);
} finally {
await context.close();
}
});
it('works on Chromium', async () => {
const { context, page } = await createDevicePage(device, 'about:blank', 'chromium');
try {