Compare commits

..
Author SHA1 Message Date
Codeman maintainer e4a85fabcd 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>
2026-11-15 14:00:34 +01:00
6 changed files with 176 additions and 103 deletions

No files matched your search

-5
View File
@@ -1,5 +0,0 @@
---
"aicodeman": patch
---
**Mac app: pasting an image works.** ⌘V with a copied picture in a session's terminal did nothing in the Mac app, while the same server worked in a browser. Codeman's paste asks the browser for the clipboard first, and inside the app WebKit answers that with a hidden "Paste" permission menu that held up the real paste. The app now declines that request the way Chrome does, so the picture uploads and its path lands in the prompt, the same as in a browser. Screenshots, images copied from an app, files copied in Finder and plain text all paste with one ⌘V, also from servers on older Codeman versions.
-24
View File
@@ -59,15 +59,6 @@ pub fn respond(request: Request<Vec<u8>>) -> Response<Cow<'static, [u8]>> {
/// server restarted, and nothing in the page asks for the login again.
/// - defines `__codemanDesktopRefused(id)` (not enumerable) for
/// [`refused_script`].
/// - answers `document.execCommand('paste')` with false, the way Chromium
/// does, without asking WebKit. Codeman's ⌘V handler calls it on its hidden
/// paste trap (`_handleImagePaste` in src/web/public/image-input.js). From a
/// WKWebView, WebKit answers that call by opening its "Paste" access menu at
/// the last click and holding the page until it is picked or the clipboard
/// changes, so the key's own paste, the one that carries a copied image, got
/// stuck behind it and a pasted picture never arrived. With this answer each
/// ⌘V delivers exactly one paste event to the trap, measured on macOS 27.2
/// for image data, a screenshot, a file copied in Finder, and text.
pub const HOST_SHIM: &str = r#"(function () {
'use strict';
if (!/^https?:$/.test(location.protocol) || window.CodemanHost) return;
@@ -122,19 +113,6 @@ pub const HOST_SHIM: &str = r#"(function () {
}
});
// Cmd+V: Codeman's paste trap calls document.execCommand('paste'). WebKit
// answers that from a WKWebView with its "Paste" access menu and holds the
// page until someone picks it, and the key's own paste (the one carrying a
// copied image) is stuck behind it. Refuse it as Chromium does; every other
// command reaches WebKit unchanged.
var nativeExec = typeof Document === 'function' ? Document.prototype.execCommand : null;
if (typeof nativeExec === 'function') {
Document.prototype.execCommand = function execCommand(command) {
if (typeof command === 'string' && command.toLowerCase() === 'paste') return false;
return nativeExec.apply(this, arguments);
};
}
var markDownload = function (ev) {
if (ev.button > 1) return;
var a = link(ev);
@@ -300,8 +278,6 @@ mod tests {
"'auxclick'",
"MAX_URL = 4096",
"typeof id === 'string' && id !== ''",
"Document.prototype.execCommand = function execCommand(command)",
"command.toLowerCase() === 'paste') return false",
] {
assert!(HOST_SHIM.contains(needle), "{needle}");
}
+21 -6
View File
@@ -1039,15 +1039,30 @@ html.mobile-init .file-browser-panel {
bottom: calc(var(--safe-area-bottom) + var(--chrome-overlap, 0px));
}
/* When keyboard is visible the JS translateY already accounts for the full
distance from the visual-viewport bottom to the layout-viewport bottom
(keyboard + Safari bar). Remove the CSS Safari-bar offset to avoid
double-counting, which otherwise creates a visible gap above the keyboard. */
/* With the keyboard up the bars sit directly on it. The JS translateY already
lifts them by the whole distance from the layout-viewport bottom to the
visual-viewport bottom (keyboard, plus Safari's bar where there is one), so
the Safari-bar offset is not added again here. Nor is the bottom safe area:
the keyboard covers the home-indicator strip it reserves. Keeping it (34px
on a Face ID iPhone, since the page sets viewport-fit=cover) left an empty
band between the toolbar and the keyboard, and worse, pushed the bars 34px
above the box main's keyboard padding reserves for them (84px, the two
bars only, set by KeyboardHandler), so the terminal's last row, the end of
the prompt being typed, was painted under the accessory bar. The second
selector of each pair outranks `.ios-device.safari-browser .toolbar`. */
.keyboard-visible .toolbar,
.keyboard-visible.ios-device.safari-browser .toolbar {
bottom: var(--safe-area-bottom);
bottom: 0;
}
.keyboard-visible .keyboard-accessory-bar,
.keyboard-visible.ios-device.safari-browser .keyboard-accessory-bar {
bottom: calc(var(--safe-area-bottom) + 40px);
bottom: 40px;
}
/* The CJK textarea stacks on the accessory bar, so it drops the same strip
(styles.css adds --safe-area-bottom for every touch device; on an iPad the
JS sets `bottom` inline and this rule never applies, being phone-only). */
.touch-device.keyboard-visible #cjkInput.cjk-input-visible {
bottom: 84px;
}
/* Show case selector in center */
-68
View File
@@ -1,68 +0,0 @@
/**
* @fileoverview The Mac app's host shim refuses `document.execCommand('paste')`.
*
* Codeman's Cmd+V handler (`_handleImagePaste`, src/web/public/image-input.js)
* calls `document.execCommand('paste')` on its hidden paste trap. In a
* WKWebView WebKit answers that call with its "Paste" access menu and holds the
* page until it is picked, so the key's own paste, which carries a copied
* image, never reached the trap. The shim the app injects into every server
* page (`HOST_SHIM`, packages/desktop/src/assets.rs) answers the command with
* false, as Chromium does, and leaves every other command to WebKit.
*
* Runs the shim's real text, cut out of assets.rs, in a vm with a stub
* Document, so a change to the Rust string is what these tests see.
*/
import { readFileSync } from 'node:fs';
import { resolve } from 'node:path';
import vm from 'node:vm';
import { describe, expect, it, vi } from 'vitest';
const assetsRs = readFileSync(resolve(import.meta.dirname, '../packages/desktop/src/assets.rs'), 'utf8');
const shim = /pub const HOST_SHIM: &str = r#"([\s\S]*?)"#;/.exec(assetsRs)?.[1];
function load(protocol = 'https:') {
if (!shim) throw new Error('HOST_SHIM not found in assets.rs');
const nativeExec = vi.fn(function (this: unknown) {
return true;
});
function Document() {}
Document.prototype.execCommand = nativeExec;
const document = Object.create(Document.prototype) as { execCommand: (...args: unknown[]) => boolean };
const sandbox: Record<string, unknown> = {
Document,
document,
URL,
location: { protocol, href: `${protocol}//atlas.example/`, origin: `${protocol}//atlas.example` },
addEventListener: vi.fn(),
open: vi.fn(),
fetch: vi.fn(),
ipc: { postMessage: vi.fn() },
};
sandbox.window = sandbox;
vm.runInNewContext(shim, sandbox);
return { document, nativeExec, sandbox };
}
describe('desktop host shim: execCommand paste', () => {
it('answers paste with false and never asks WebKit', () => {
const { document, nativeExec } = load();
expect(document.execCommand('paste')).toBe(false);
expect(document.execCommand('Paste')).toBe(false);
expect(nativeExec).not.toHaveBeenCalled();
});
it('hands every other command to WebKit with its arguments and document', () => {
const { document, nativeExec } = load();
expect(document.execCommand('copy')).toBe(true);
expect(document.execCommand('insertText', false, 'hi')).toBe(true);
expect(nativeExec).toHaveBeenNthCalledWith(1, 'copy');
expect(nativeExec).toHaveBeenNthCalledWith(2, 'insertText', false, 'hi');
expect(nativeExec.mock.contexts[0]).toBe(document);
});
it('leaves a page that is not http(s) alone', () => {
const { document, nativeExec } = load('file:');
expect(document.execCommand('paste')).toBe(true);
expect(nativeExec).toHaveBeenCalledWith('paste');
});
});
+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 {