fix(mobile): pinned field on phones: swipes, focus scroll, viewport pan, iOS lift

Found on a real Android phone (Chrome) and iPhone (Safari) with Send on Enter:

- A swipe that started on the live screen closed the keyboard: the content
  touchstart blurred the focused input before the gesture was known to be a
  tap or a scroll. It now skips the visible #cjkInput
  (_contentTouchStartBlurs()); a real tap still closes it (inert content, a
  link, a long press).
- Focusing the field scrolled the terminal off screen: KeyboardHandler's
  focusin scrollIntoView({ block: 'center' }) centred the fixed field in its
  ancestors. isInputElement() skips #cjkInput like xterm's inputs.
- Android pans the visual viewport to reveal the field (offsetTop 285 in a
  458/744 viewport), leaving only the terminal's last line visible. On phones
  .app now follows visualViewport.offsetTop while the keyboard is up, and the
  fixed bars inside .app are lifted from .app's bottom, so a partial pan does
  not lift them twice. Non-phone branches and resetLayout() clear the shift.
- On iOS the first keyboard open reported innerHeight as the visual height
  (323 vs 640), zeroing the bars' lift; the layout height is now the larger of
  innerHeight and documentElement.clientHeight.

Tests in test/keyboard-handler-pinned-field.test.ts and
test/terminal-touch-tap.test.ts; docs in architecture-invariants and
src/web/CLAUDE.md; changeset sentence.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Kamil KaliszandClaude Opus 5.5 committed 2026-11-17 13:45:20 +01:00
1 parent 3c5b7e2199
commit e85bb83353
7 files changed
+272 -16

No files matched your search

+41 -1
View File
@@ -139,6 +139,28 @@ describe('terminal touch tap mouse guard', () => {
expect(app._isMobileTerminalInputFocused()).toBe(true);
});
it('a content touchstart blurs xterm input but leaves the pinned CJK field focused', () => {
const { app, setActiveElement } = loadTerminalUiHarness();
setActiveElement({ id: '', classList: { contains: (c: string) => c === 'xterm-helper-textarea' } });
expect(app._contentTouchStartBlurs()).toBe(true);
// A swipe that starts on the live screen must not close the keyboard the field owns.
setActiveElement({ id: 'cjkInput', classList: { contains: () => false } });
expect(app._contentTouchStartBlurs()).toBe(false);
setActiveElement(null);
expect(app._contentTouchStartBlurs()).toBe(true);
});
it('the content touchstart only blurs through _contentTouchStartBlurs()', () => {
// The touchstart listener lives in initTerminal, which this harness does not run,
// so pin its one line: an unconditional blur there closes the pinned field's
// keyboard on every swipe that starts on the live screen.
const code = readFileSync(resolve(import.meta.dirname, '../src/web/public/terminal-ui.js'), 'utf8');
const branch = code.slice(code.indexOf("if (touchStartIntent === 'content') {"));
const body = branch.slice(0, branch.indexOf('// Hold still and this press becomes a text selection.'));
expect(body).toContain('if (this._contentTouchStartBlurs()) this._blurMobileTerminalInput();');
expect(body.match(/_blurMobileTerminalInput\(\)/g)).toHaveLength(1);
});
it('routes a readback row to the TUI while keeping the prompt row as keyboard input', () => {
const { app } = loadTerminalUiHarness();
app.activeSessionId = 'sess-1';
@@ -967,9 +989,27 @@ describe('terminal link tap', () => {
app._isOutsideWorktreePath = () => false;
windowRef.open = vi.fn();
app.registerFilePathLinkProvider();
return { app, windowRef, sent };
return { app, windowRef, sent, setActiveElement: harness.setActiveElement };
}
it('a link tap closes the keyboard of the pinned CJK field, which touchstart left focused', () => {
const line = 'Login at https://claude.ai/oauth/authorize?code=true&client_id=abc to finish';
const { app, setActiveElement } = linkHarness([line, '', '❯ ']);
const cjk = { id: 'cjkInput', classList: { contains: () => false }, blur: vi.fn() };
setActiveElement(cjk);
expect(app._handleMobileTerminalTap(at(line.indexOf('https')), false, 'content')).toBe('link');
expect(cjk.blur).toHaveBeenCalled();
});
it('a link tap leaves focus alone otherwise (touchstart already blurred xterm input)', () => {
const line = 'Login at https://claude.ai/oauth/authorize?code=true&client_id=abc to finish';
const { app, setActiveElement } = linkHarness([line, '', '❯ ']);
const other = { id: '', classList: { contains: () => false }, blur: vi.fn() };
setActiveElement(other);
expect(app._handleMobileTerminalTap(at(line.indexOf('https')), false, 'content')).toBe('link');
expect(other.blur).not.toHaveBeenCalled();
});
it('opens a URL under the finger in a new tab', () => {
const line = 'Login at https://claude.ai/oauth/authorize?code=true&client_id=abc to finish';
const { app, windowRef } = linkHarness([line, '', '❯ ']);