mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 13:09:33 +01:00
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:
1 parent
3c5b7e2199
commit
e85bb83353
7 files changed
+272
-16
No files matched your search
@@ -2,4 +2,4 @@
|
|||||||
"aicodeman": patch
|
"aicodeman": patch
|
||||||
---
|
---
|
||||||
|
|
||||||
Add a per-device "Send on Enter" mode for the pinned CJK input field, so phone users can scroll the terminal while a typed answer waits in the field until Enter. The phone toolbar's Enter button now also sends the CJK field's text while the field is visible, in live mode too.
|
Add a per-device "Send on Enter" mode for the pinned CJK input field, so phone users can scroll the terminal while a typed answer waits in the field until Enter. The phone toolbar's Enter button now also sends the CJK field's text while the field is visible, in live mode too. On phones the keyboard layout also gets sturdier for everyone: a swipe that starts on the live screen no longer closes the pinned field's keyboard, the app follows the browser when it pans the screen to a focused field instead of leaving only the terminal's last line visible, and on iOS the toolbar, accessory bar and field sit on the keyboard on its first open instead of behind it.
|
||||||
@@ -1139,7 +1139,9 @@ Tests: `test/tab-rail-search.test.ts` (gate) and `test/tab-rail-search.browser.t
|
|||||||
|
|
||||||
**A fold is not a keyboard.** `KeyboardHandler.handleViewportResize()` (mobile-handlers.js) used to read any visual-viewport height drop over 150px as the keyboard appearing. A virtual keyboard only ever takes HEIGHT, so a resize that changes the WIDTH is the device changing shape (a rotation, or a foldable opening or closing) and is skipped by both detection branches. Closing an iPhone Duo (626→466pt wide, 890→678pt tall) otherwise latched `keyboardVisible` with no keyboard on screen: the accessory bar appeared, `main` grew 84px of dead padding, and `updateAppHeight()`, which bails while the keyboard is up, stopped refreshing `--app-height`. The latch was sticky because clearing it needed the height back within 100px of a baseline belonging to a display the user was no longer looking at. The shape branch re-baselines instead, which is also what lets a keyboard opened after the fold be detected, and `init()` seeds `lastViewportWidth` so the first resize of the page is not itself read as a shape change.
|
**A fold is not a keyboard.** `KeyboardHandler.handleViewportResize()` (mobile-handlers.js) used to read any visual-viewport height drop over 150px as the keyboard appearing. A virtual keyboard only ever takes HEIGHT, so a resize that changes the WIDTH is the device changing shape (a rotation, or a foldable opening or closing) and is skipped by both detection branches. Closing an iPhone Duo (626→466pt wide, 890→678pt tall) otherwise latched `keyboardVisible` with no keyboard on screen: the accessory bar appeared, `main` grew 84px of dead padding, and `updateAppHeight()`, which bails while the keyboard is up, stopped refreshing `--app-height`. The latch was sticky because clearing it needed the height back within 100px of a baseline belonging to a display the user was no longer looking at. The shape branch re-baselines instead, which is also what lets a keyboard opened after the fold be detected, and `init()` seeds `lastViewportWidth` so the first resize of the page is not itself read as a shape change.
|
||||||
|
|
||||||
**With the keyboard up, the new baseline is `window.innerHeight`, never the shrunk visual height.** The page sets no `interactive-widget`, so the default resizes-visual mode holds on both engines: the keyboard shrinks only the visual viewport and the layout viewport stays the display's full height (`updateLayoutForKeyboard()` relies on the same fact). The first version baselined to the shrunk height, which made `heightDiff` 0, so the settle event the OS animation fires at the new width (or any later address-bar drift) satisfied the hide branch and ran `onKeyboardHide()` with the keyboard still on screen: accessory bar hidden, the toolbar lift dropped, `main`'s padding cleared. It could not recover, because no further 150px drop can re-arm the show branch against a baseline already sitting at the shrunk height. Reproduced against the real handler in the vm harness with both the fold flavour (626x590 → 466x378 → 466x378) and the rotation flavour (393x359 → 852x150 → 852x160); `test/viewport-shape-change.test.ts` models the two heights separately and pins both.
|
**With the keyboard up, the new baseline is `window.innerHeight`, never the shrunk visual height.** The page sets no `interactive-widget`, so the default resizes-visual mode holds on both engines: the keyboard shrinks only the visual viewport and the layout viewport stays the display's full height (`updateLayoutForKeyboard()` relies on the same fact, but measures that height as the larger of `innerHeight` and `documentElement.clientHeight`: on a first keyboard open iOS Safari briefly reported `innerHeight` as the shrunk visual height, 323 against a 640 layout viewport, which zeroed the bars' lift). The first version baselined to the shrunk height, which made `heightDiff` 0, so the settle event the OS animation fires at the new width (or any later address-bar drift) satisfied the hide branch and ran `onKeyboardHide()` with the keyboard still on screen: accessory bar hidden, the toolbar lift dropped, `main`'s padding cleared. It could not recover, because no further 150px drop can re-arm the show branch against a baseline already sitting at the shrunk height. Reproduced against the real handler in the vm harness with both the fold flavour (626x590 → 466x378 → 466x378) and the rotation flavour (393x359 → 852x150 → 852x160); `test/viewport-shape-change.test.ts` models the two heights separately and pins both.
|
||||||
|
|
||||||
|
**A pan of the visual viewport moves `.app` with it.** In resizes-visual mode a focused field that starts behind the keyboard makes Android pan the visual viewport down to reveal it: the pinned `#cjkInput` sits at the bottom of the layout viewport, and Chrome panned 285px with a 458px visual viewport in a 744px layout one. `.app` is sized to the visual viewport (`--app-height`) but laid out at the top of the layout viewport, so that pan left only the terminal's last line on screen. On phones `updateLayoutForKeyboard()` therefore sets `.app`'s `translateY` to `visualViewport.offsetTop` while the keyboard is up, whatever has focus (no pan, the usual case, moves nothing), and clears it on every other branch and in `resetLayout()`. ⚠️ The transform makes `.app` the box its `position: fixed` children are placed against (header, `.toolbar`, the accessory bar, which is inserted before the toolbar, and `#cjkInput`), so their lift is measured from `.app`'s bottom (`insideLift`), not the layout viewport's: lifting them by the layout gap as well floated them above the keyboard on a partial pan. The case sheet lives outside `.app` and keeps the layout lift. Separately, `KeyboardHandler.isInputElement()` skips `#cjkInput` like xterm's inputs, because the focusin `scrollIntoView({ block: 'center' })` centred the fixed field in its ancestors and pushed the terminal off screen. Pinned by `test/keyboard-handler-pinned-field.test.ts`.
|
||||||
|
|
||||||
**The hinge is a reserved region, and the CSS is inert by construction.** The CSS Viewport Segments media features report two segments only while a foldable is actually bent; `--fold-inline-end` / `--fold-block-end` (end of styles.css) measure the strip to keep clear from the LEADING segment (`env(viewport-segment-right 0 0)` and `env(viewport-segment-bottom 0 0)`, physical sides in every text direction) and are `0px` on everything else. The seven centred overlays are all `position: fixed; inset: 0` flex boxes; each shrinks its CONTENT box with padding rather than the box itself, so the backdrop still covers the far side of the fold and still swallows taps there. The cascade traps, each measured in headless Chromium against styles.css + mobile.css in index.html link order: (1) a later `padding-right` longhand beats the earlier `padding` shorthand it composes with, so each fold rule re-states the overlay's own gutter; (2) a base gutter that a LATER `@media` block overrides needs its own fold restatement in that block on a ZERO base, since the unconditional rules at the end of the file otherwise put the gutter back (the phone path picker and path preview drop to `padding: 0` under 600px and came back at 16px and 18px on every phone); (3) a compound rule written to outrank a mobile.css shorthand must be scoped to the band where that shorthand applies, because outside it there is no gutter to compose with (the palette's `.modal.command-palette-modal` added 0.75rem at 393, 900 and 1400px and pushed the shell 6px off centre, and inside the band it lost its bottom gutter to the shorthand until it restated that side too); (4) mobile.css loads AFTER styles.css, so a same-specificity rule there wins under its own breakpoint (the response viewer's `max-height: 92dvh` under 600px beat the tabletop cap, which now has a twin at the end of mobile.css). `test/foldable-layout.test.ts` DERIVES the overlay list from the stylesheet, simulates the cascade across both files at every breakpoint with and without the fold rules, and requires the two results to differ by exactly the fold strip, so each of the four fails there instead of on hardware nobody has.
|
**The hinge is a reserved region, and the CSS is inert by construction.** The CSS Viewport Segments media features report two segments only while a foldable is actually bent; `--fold-inline-end` / `--fold-block-end` (end of styles.css) measure the strip to keep clear from the LEADING segment (`env(viewport-segment-right 0 0)` and `env(viewport-segment-bottom 0 0)`, physical sides in every text direction) and are `0px` on everything else. The seven centred overlays are all `position: fixed; inset: 0` flex boxes; each shrinks its CONTENT box with padding rather than the box itself, so the backdrop still covers the far side of the fold and still swallows taps there. The cascade traps, each measured in headless Chromium against styles.css + mobile.css in index.html link order: (1) a later `padding-right` longhand beats the earlier `padding` shorthand it composes with, so each fold rule re-states the overlay's own gutter; (2) a base gutter that a LATER `@media` block overrides needs its own fold restatement in that block on a ZERO base, since the unconditional rules at the end of the file otherwise put the gutter back (the phone path picker and path preview drop to `padding: 0` under 600px and came back at 16px and 18px on every phone); (3) a compound rule written to outrank a mobile.css shorthand must be scoped to the band where that shorthand applies, because outside it there is no gutter to compose with (the palette's `.modal.command-palette-modal` added 0.75rem at 393, 900 and 1400px and pushed the shell 6px off centre, and inside the band it lost its bottom gutter to the shorthand until it restated that side too); (4) mobile.css loads AFTER styles.css, so a same-specificity rule there wins under its own breakpoint (the response viewer's `max-height: 92dvh` under 600px beat the tabletop cap, which now has a twin at the end of mobile.css). `test/foldable-layout.test.ts` DERIVES the overlay list from the stylesheet, simulates the cascade across both files at every breakpoint with and without the fold rules, and requires the two results to differ by exactly the fold strip, so each of the four fails there instead of on hardware nobody has.
|
||||||
|
|
||||||
@@ -1299,6 +1301,8 @@ Tests: `test/mobile-prompt-composer.test.ts` (in the CI gate, deliberately not u
|
|||||||
|
|
||||||
**(2)** In `_handleMobileTerminalTap`, a second tap on **inert `content`** (`startedWithTerminalFocus`) blurs instead of re-focusing. ⚠️ Scoped to `content` on purpose: the prompt row (`input`) keeps focus-then-position so a second tap still places the caret, and actionable rows blur earlier via `_isActionableMobileTerminalTap`.
|
**(2)** In `_handleMobileTerminalTap`, a second tap on **inert `content`** (`startedWithTerminalFocus`) blurs instead of re-focusing. ⚠️ Scoped to `content` on purpose: the prompt row (`input`) keeps focus-then-position so a second tap still places the caret, and actionable rows blur earlier via `_isActionableMobileTerminalTap`.
|
||||||
|
|
||||||
|
⚠️ **The pinned CJK field keeps its focus through a swipe.** `initTerminal`'s touchstart blurs the focused input on `content` before the gesture is known to be a tap or a scroll. For xterm's helper textarea that blur, with the `preventDefault` beside it, is what keeps the compatibility click from opening the keyboard. The visible `#cjkInput` owns the keyboard instead, so `_contentTouchStartBlurs()` leaves it focused; blurring it closed the keyboard on every swipe that started on the live screen. A real tap still closes it: inert content through (2), a link in `_handleMobileTerminalTap`'s link branch (which blurs because touchstart did not), a long press in `_beginTouchSelection`. A sideways session swipe keeps it open, since the field's draft is per session. Pinned by `test/terminal-touch-tap.test.ts`.
|
||||||
|
|
||||||
⚠️ **A scroll ends in `touchend` too** — dismissing there closes the keyboard and drops the composer mid-read, so travel is tracked from `touchstart` and multi-touch is never a tap. Both classifiers MUST share one threshold: `initTerminal`'s `TAP_THRESHOLD` reads `MOBILE_KEYBOARD_DISMISS_TAP_SLOP`, since a gesture the terminal calls a scroll and the dismiss handler calls a tap is exactly that bug.
|
⚠️ **A scroll ends in `touchend` too** — dismissing there closes the keyboard and drops the composer mid-read, so travel is tracked from `touchstart` and multi-touch is never a tap. Both classifiers MUST share one threshold: `initTerminal`'s `TAP_THRESHOLD` reads `MOBILE_KEYBOARD_DISMISS_TAP_SLOP`, since a gesture the terminal calls a scroll and the dismiss handler calls a tap is exactly that bug.
|
||||||
|
|
||||||
⚠️ **An accessory key that keeps the keyboard up must not take focus on the press.** The keys that act on the terminal and leave the keyboard open (`ACCESSORY_REFOCUS_ACTIONS` in keyboard-accessory.js: scroll, arrows, Tab, Shift+Tab, Ctrl, Esc, clear input and the rest) cancel the `mousedown` default, the same pattern as the Attach input, so the hidden textarea keeps focus through the press; the `terminal.focus()` in the click handler stays as the fallback. Letting the tap blur the terminal and refocusing it afterwards made every such key start a keyboard dismissal, a blur/focus pair per tap that shifted the toolbar each time. A first tap on clear/compact only arms the confirm and is treated the same; the confirming tap, and keys that open a dialog or dismiss the keyboard on purpose, keep the default. Pinned against the real module by `test/accessory-keeps-terminal-focus.test.ts`.
|
⚠️ **An accessory key that keeps the keyboard up must not take focus on the press.** The keys that act on the terminal and leave the keyboard open (`ACCESSORY_REFOCUS_ACTIONS` in keyboard-accessory.js: scroll, arrows, Tab, Shift+Tab, Ctrl, Esc, clear input and the rest) cancel the `mousedown` default, the same pattern as the Attach input, so the hidden textarea keeps focus through the press; the `terminal.focus()` in the click handler stays as the fallback. Letting the tap blur the terminal and refocusing it afterwards made every such key start a keyboard dismissal, a blur/focus pair per tap that shifted the toolbar each time. A first tap on clear/compact only arms the confirm and is treated the same; the confirming tap, and keys that open a dialog or dismiss the keyboard on purpose, keep the default. Pinned against the real module by `test/accessory-keeps-terminal-focus.test.ts`.
|
||||||
|
|||||||
+1
-1
@@ -82,7 +82,7 @@ Frontend JS modules have `@fileoverview` with `@dependency`/`@loadorder` tags. L
|
|||||||
|
|
||||||
**WebSocket output-gap reconcile** (`_wsOutputGapSession`, app.js): output frames carry no sequence number, so an unintentional WS close while SSE stays up marks the session and the next open reconciles. ⚠️ The marker is cleared only once a repaint actually happened (`_markTerminalBufferReconciled()`, never in a `finally`). → [architecture-invariants#websocket-output-gap-reconcile](../../docs/architecture-invariants.md#websocket-output-gap-reconcile)
|
**WebSocket output-gap reconcile** (`_wsOutputGapSession`, app.js): output frames carry no sequence number, so an unintentional WS close while SSE stays up marks the session and the next open reconciles. ⚠️ The marker is cleared only once a repaint actually happened (`_markTerminalBufferReconciled()`, never in a `finally`). → [architecture-invariants#websocket-output-gap-reconcile](../../docs/architecture-invariants.md#websocket-output-gap-reconcile)
|
||||||
|
|
||||||
**Dismissing the on-screen keyboard** (`terminal-ui.js`): two gestures blur the terminal's hidden textarea. (1) `_installMobileKeyboardDismiss()`, a document `touchend` that must never fire inside `#terminalContainer` or on a control (`MOBILE_KEYBOARD_DISMISS_EXEMPT_SELECTOR`, via `closest()`; roving-tabindex items sit at `tabindex=-1`, so the grouped rail's are listed as `[role="treeitem"]`). (2) In `_handleMobileTerminalTap`, a second tap on inert `content` blurs; the prompt row keeps focus-then-position. ⚠️ A scroll also ends in `touchend`: both classifiers must share one threshold (`TAP_THRESHOLD` reads `MOBILE_KEYBOARD_DISMISS_TAP_SLOP`), and multi-touch is never a tap. ⚠️ An accessory key that keeps the keyboard up (`ACCESSORY_REFOCUS_ACTIONS`, keyboard-accessory.js) cancels its `mousedown` default, so the press does not blur the terminal; the click-time `terminal.focus()` stays as the fallback. Letting the tap blur and refocusing afterwards made every such key start a dismissal, a blur/focus pair per tap. A first tap on clear/compact only arms the confirm and is treated the same (`test/accessory-keeps-terminal-focus.test.ts`). ⚠️ CI cannot see the only test for (1): run `npm run test:mobile -- test/mobile/keyboard.test.ts` by hand and diff the FAIL list against master. → [architecture-invariants#dismissing-the-on-screen-keyboard](../../docs/architecture-invariants.md#dismissing-the-on-screen-keyboard)
|
**Dismissing the on-screen keyboard** (`terminal-ui.js`): two gestures blur the terminal's hidden textarea. (1) `_installMobileKeyboardDismiss()`, a document `touchend` that must never fire inside `#terminalContainer` or on a control (`MOBILE_KEYBOARD_DISMISS_EXEMPT_SELECTOR`, via `closest()`; roving-tabindex items sit at `tabindex=-1`, so the grouped rail's are listed as `[role="treeitem"]`). (2) In `_handleMobileTerminalTap`, a second tap on inert `content` blurs; the prompt row keeps focus-then-position. ⚠️ A scroll also ends in `touchend`: both classifiers must share one threshold (`TAP_THRESHOLD` reads `MOBILE_KEYBOARD_DISMISS_TAP_SLOP`), and multi-touch is never a tap. ⚠️ An accessory key that keeps the keyboard up (`ACCESSORY_REFOCUS_ACTIONS`, keyboard-accessory.js) cancels its `mousedown` default, so the press does not blur the terminal; the click-time `terminal.focus()` stays as the fallback. Letting the tap blur and refocusing afterwards made every such key start a dismissal, a blur/focus pair per tap. A first tap on clear/compact only arms the confirm and is treated the same (`test/accessory-keeps-terminal-focus.test.ts`). ⚠️ The content touchstart blur skips the visible `#cjkInput` (`_contentTouchStartBlurs()`), or every swipe on the live screen closed its keyboard; a tap still closes it (inert content, a link, a long press). On phones `updateLayoutForKeyboard()` also moves `.app` by `visualViewport.offsetTop` while the keyboard is up, and lifts the fixed bars inside it from `.app`'s bottom (architecture-invariants, Folding devices section). ⚠️ CI cannot see the only test for (1): run `npm run test:mobile -- test/mobile/keyboard.test.ts` by hand and diff the FAIL list against master. → [architecture-invariants#dismissing-the-on-screen-keyboard](../../docs/architecture-invariants.md#dismissing-the-on-screen-keyboard)
|
||||||
|
|
||||||
**Phone toolbar: Enter replaces Shell** (post-1.8.0): inside `@media (max-width: 599px)` `btn-shell` is `display:none` and `btn-enter` takes its slot (`order: 4`); starting a shell moved into the Run dropdown (`Terminal / Shell` → `setRunMode('shell')` → `run()` → `runShell()`, button label "Run SH"). `runMode` is `z.string().max(20)` server-side, so new modes need no schema change. Desktop and tablet keep the green Run Shell button unchanged.
|
**Phone toolbar: Enter replaces Shell** (post-1.8.0): inside `@media (max-width: 599px)` `btn-shell` is `display:none` and `btn-enter` takes its slot (`order: 4`); starting a shell moved into the Run dropdown (`Terminal / Shell` → `setRunMode('shell')` → `run()` → `runShell()`, button label "Run SH"). `runMode` is `z.string().max(20)` server-side, so new modes need no schema change. Desktop and tablet keep the green Run Shell button unchanged.
|
||||||
|
|
||||||
|
|||||||
@@ -435,21 +435,44 @@ const KeyboardHandler = {
|
|||||||
// BEHIND the keyboard with its own search box out of sight.
|
// BEHIND the keyboard with its own search box out of sight.
|
||||||
const caseSheet = document.querySelector('.mobile-case-picker.active .mobile-case-picker-sheet');
|
const caseSheet = document.querySelector('.mobile-case-picker.active .mobile-case-picker-sheet');
|
||||||
|
|
||||||
|
// A focused field that starts behind the keyboard (the pinned CJK / Send on
|
||||||
|
// Enter field) makes Android pan the visual viewport down to reveal it (measured
|
||||||
|
// on Chrome: offsetTop 285px with a 458px visual viewport in a 744px layout one).
|
||||||
|
// The app is sized to the visual viewport but laid out at the top of the layout
|
||||||
|
// viewport, so that pan left only the terminal's last line on screen. On phones,
|
||||||
|
// follow the pan while the keyboard is up, whatever has focus: without a pan
|
||||||
|
// (offsetTop 0, the usual case) nothing moves, and a focus change that keeps the
|
||||||
|
// pan cannot drop the shift. Every other branch clears it.
|
||||||
|
// ⚠️ The transform makes .app the box its position:fixed children (header,
|
||||||
|
// toolbar, accessory bar, the field) are placed against, so their keyboard lift
|
||||||
|
// below is measured from .app's bottom, not the layout viewport's, or they would
|
||||||
|
// be lifted twice on a partial pan. The case sheet lives outside .app.
|
||||||
|
const appEl = document.querySelector('.app');
|
||||||
|
const pan = isSmallMedium ? Math.round(window.visualViewport.offsetTop || 0) : 0;
|
||||||
|
if (appEl) appEl.style.transform = pan > 0 ? `translateY(${pan}px)` : '';
|
||||||
|
// The layout viewport's height, which position:fixed bottoms are measured from.
|
||||||
|
// ⚠️ Not window.innerHeight alone: on the first keyboard open after focusing the
|
||||||
|
// pinned field, iOS Safari reported innerHeight as the shrunk visual height (323)
|
||||||
|
// while the layout viewport stayed 640 (documentElement.clientHeight), so the lift
|
||||||
|
// came out 0 and the bars stayed behind the keyboard. Earlier a delayed
|
||||||
|
// scrollIntoView re-ran this pass once innerHeight had caught up; without it the
|
||||||
|
// stale value stuck. The larger of the two cannot be stale in that direction.
|
||||||
|
const layoutHeight = Math.max(window.innerHeight, document.documentElement?.clientHeight || 0);
|
||||||
|
const visualBottom = window.visualViewport.offsetTop + window.visualViewport.height;
|
||||||
|
const keyboardOffset = Math.max(0, layoutHeight - visualBottom);
|
||||||
|
const insideLift = pan > 0 && appEl ? Math.max(0, pan + appEl.offsetHeight - visualBottom) : keyboardOffset;
|
||||||
|
|
||||||
if (isSmallMedium) {
|
if (isSmallMedium) {
|
||||||
// Phones/small tablets: toolbar and accessory bar are position:fixed
|
// Phones/small tablets: toolbar and accessory bar are position:fixed
|
||||||
// via CSS. Use translateY to lift them above the keyboard.
|
// via CSS. Use translateY to lift them above the keyboard.
|
||||||
const toolbar = document.querySelector('.toolbar');
|
const toolbar = document.querySelector('.toolbar');
|
||||||
const main = document.querySelector('.main');
|
const main = document.querySelector('.main');
|
||||||
|
|
||||||
const layoutHeight = window.innerHeight;
|
|
||||||
const visualBottom = window.visualViewport.offsetTop + window.visualViewport.height;
|
|
||||||
const keyboardOffset = Math.max(0, layoutHeight - visualBottom);
|
|
||||||
|
|
||||||
if (toolbar) {
|
if (toolbar) {
|
||||||
toolbar.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
toolbar.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||||
}
|
}
|
||||||
if (accessoryBar) {
|
if (accessoryBar) {
|
||||||
accessoryBar.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
accessoryBar.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||||
}
|
}
|
||||||
if (caseSheet) {
|
if (caseSheet) {
|
||||||
caseSheet.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
caseSheet.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
||||||
@@ -476,11 +499,8 @@ const KeyboardHandler = {
|
|||||||
// CJK textarea positioning (always position:fixed on touch devices).
|
// CJK textarea positioning (always position:fixed on touch devices).
|
||||||
if (cjkInput?.classList.contains('cjk-input-visible') && keyboardHeight > 0) {
|
if (cjkInput?.classList.contains('cjk-input-visible') && keyboardHeight > 0) {
|
||||||
if (isSmallMedium) {
|
if (isSmallMedium) {
|
||||||
// Phones: use translateY like toolbar/accessory bar.
|
// Phones: use translateY like toolbar/accessory bar (it sits inside .app too).
|
||||||
const layoutHeight = window.innerHeight;
|
cjkInput.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||||
const visualBottom = window.visualViewport.offsetTop + window.visualViewport.height;
|
|
||||||
const keyboardOffset = Math.max(0, layoutHeight - visualBottom);
|
|
||||||
cjkInput.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
|
||||||
cjkInput.style.bottom = '';
|
cjkInput.style.bottom = '';
|
||||||
} else {
|
} else {
|
||||||
// iPad: direct bottom = keyboard + accessory bar height.
|
// iPad: direct bottom = keyboard + accessory bar height.
|
||||||
@@ -503,7 +523,11 @@ const KeyboardHandler = {
|
|||||||
// keyboard was still up must still have its inline offset cleared, or the
|
// keyboard was still up must still have its inline offset cleared, or the
|
||||||
// next open slides in already displaced.
|
// next open slides in already displaced.
|
||||||
const caseSheet = document.querySelector('.mobile-case-picker-sheet');
|
const caseSheet = document.querySelector('.mobile-case-picker-sheet');
|
||||||
|
const appEl = document.querySelector('.app');
|
||||||
|
|
||||||
|
if (appEl) {
|
||||||
|
appEl.style.transform = '';
|
||||||
|
}
|
||||||
if (toolbar) {
|
if (toolbar) {
|
||||||
toolbar.style.transform = '';
|
toolbar.style.transform = '';
|
||||||
}
|
}
|
||||||
@@ -733,6 +757,11 @@ const KeyboardHandler = {
|
|||||||
if (el.closest('.xterm') || el.closest('.terminal-container')) {
|
if (el.closest('.xterm') || el.closest('.terminal-container')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
// The pinned CJK / Send on Enter field is position:fixed and lifted above the
|
||||||
|
// keyboard by updateLayoutForKeyboard(). Scrolling it into view centred it in its
|
||||||
|
// scrollable ancestors instead, which pushed the terminal off screen whenever the
|
||||||
|
// field took focus.
|
||||||
|
if (el.id === 'cjkInput') return false;
|
||||||
|
|
||||||
const tagName = el.tagName?.toLowerCase();
|
const tagName = el.tagName?.toLowerCase();
|
||||||
// Exclude type=range, type=checkbox, type=radio (don't trigger keyboard)
|
// Exclude type=range, type=checkbox, type=radio (don't trigger keyboard)
|
||||||
|
|||||||
@@ -1378,7 +1378,7 @@ Object.assign(CodemanApp.prototype, {
|
|||||||
// selectSession() ends with scrollToLastNonEmptyLine(), that made
|
// selectSession() ends with scrollToLastNonEmptyLine(), that made
|
||||||
// the keyboard unreachable after every tab switch.
|
// the keyboard unreachable after every tab switch.
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
this._blurMobileTerminalInput();
|
if (this._contentTouchStartBlurs()) this._blurMobileTerminalInput();
|
||||||
}
|
}
|
||||||
// Hold still and this press becomes a text selection. Cancelled by any
|
// Hold still and this press becomes a text selection. Cancelled by any
|
||||||
// travel past the shared tap slop below, so a scroll can never become one.
|
// travel past the shared tap slop below, so a scroll can never become one.
|
||||||
@@ -5701,6 +5701,19 @@ Object.assign(CodemanApp.prototype, {
|
|||||||
return 'content';
|
return 'content';
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a touchstart on transcript content should blur the focused terminal input.
|
||||||
|
* It does for xterm's helper textarea: that blur, with the preventDefault beside it,
|
||||||
|
* keeps the compatibility click from opening the keyboard. It must NOT for the pinned
|
||||||
|
* CJK field: at touchstart the gesture may still be a scroll, and that field owns the
|
||||||
|
* keyboard while it is visible, so blurring it closed the keyboard on every swipe that
|
||||||
|
* started on the live screen. A real tap on inert transcript still closes the keyboard
|
||||||
|
* at touchend (the startedWithTerminalFocus branch), so a tap keeps its meaning.
|
||||||
|
*/
|
||||||
|
_contentTouchStartBlurs() {
|
||||||
|
return document.activeElement?.id !== 'cjkInput';
|
||||||
|
},
|
||||||
|
|
||||||
_blurMobileTerminalInput() {
|
_blurMobileTerminalInput() {
|
||||||
const active = document.activeElement;
|
const active = document.activeElement;
|
||||||
if (
|
if (
|
||||||
@@ -5899,6 +5912,9 @@ Object.assign(CodemanApp.prototype, {
|
|||||||
) {
|
) {
|
||||||
// No focus change: a 'content' tap was already blurred by touchstart, and
|
// No focus change: a 'content' tap was already blurred by touchstart, and
|
||||||
// popping the keyboard behind a tab that is about to take over is noise.
|
// popping the keyboard behind a tab that is about to take over is noise.
|
||||||
|
// The pinned CJK field is the exception touchstart leaves focused (a swipe must
|
||||||
|
// not close its keyboard), so a tap that opens a link closes it here instead.
|
||||||
|
if (!this._contentTouchStartBlurs()) this._blurMobileTerminalInput();
|
||||||
return 'link';
|
return 'link';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,167 @@
|
|||||||
|
// Port: none (pure logic in a vm context — no browser, no server).
|
||||||
|
//
|
||||||
|
// KeyboardHandler scrolls a newly focused text field into view (scrollInputIntoView,
|
||||||
|
// `scrollIntoView({ block: 'center' })`) once the keyboard is up. The pinned CJK /
|
||||||
|
// Send on Enter field (#cjkInput) is position:fixed and already lifted above the
|
||||||
|
// keyboard by updateLayoutForKeyboard(), so scrolling it into view only centred it in
|
||||||
|
// its scrollable ancestors and pushed the terminal off screen. It must be skipped,
|
||||||
|
// like xterm's own inputs, while ordinary inputs keep the behaviour.
|
||||||
|
import { readFileSync } from 'node:fs';
|
||||||
|
import { resolve } from 'node:path';
|
||||||
|
import vm from 'node:vm';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
const SOURCE = readFileSync(resolve(import.meta.dirname, '../src/web/public/mobile-handlers.js'), 'utf8');
|
||||||
|
|
||||||
|
function loadHandler() {
|
||||||
|
const context = vm.createContext({
|
||||||
|
console,
|
||||||
|
navigator: { userAgent: 'test', maxTouchPoints: 1 },
|
||||||
|
window: { addEventListener: () => {}, matchMedia: () => ({ matches: false }), scrollTo: () => {} },
|
||||||
|
document: {
|
||||||
|
body: { classList: { add: () => {}, remove: () => {} } },
|
||||||
|
addEventListener: () => {},
|
||||||
|
getElementById: () => null,
|
||||||
|
querySelector: () => null,
|
||||||
|
},
|
||||||
|
setTimeout: () => 1,
|
||||||
|
clearTimeout: () => {},
|
||||||
|
});
|
||||||
|
vm.runInContext(`${SOURCE}\nglobalThis.__KH = KeyboardHandler;`, context, { filename: 'mobile-handlers.js' });
|
||||||
|
return (context as { __KH: any }).__KH;
|
||||||
|
}
|
||||||
|
|
||||||
|
function element(tagName: string, { id = '', inside = '' }: { id?: string; inside?: string } = {}) {
|
||||||
|
return { tagName, id, type: '', isContentEditable: false, closest: (sel: string) => (sel === inside ? {} : null) };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('KeyboardHandler.isInputElement', () => {
|
||||||
|
it('skips the pinned CJK field, which the keyboard layout positions itself', () => {
|
||||||
|
expect(loadHandler().isInputElement(element('TEXTAREA', { id: 'cjkInput' }))).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('still skips xterm inputs and still scrolls ordinary fields into view', () => {
|
||||||
|
const kh = loadHandler();
|
||||||
|
expect(kh.isInputElement(element('TEXTAREA', { inside: '.xterm' }))).toBe(false);
|
||||||
|
expect(kh.isInputElement(element('TEXTAREA', { id: 'someOtherField' }))).toBe(true);
|
||||||
|
expect(kh.isInputElement(element('INPUT'))).toBe(true);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function loadLayout({
|
||||||
|
focused = 'cjkInput',
|
||||||
|
offsetTop,
|
||||||
|
height = 458,
|
||||||
|
width = 390,
|
||||||
|
innerHeight = 744,
|
||||||
|
clientHeight = 744,
|
||||||
|
}: {
|
||||||
|
focused?: string;
|
||||||
|
offsetTop: number;
|
||||||
|
height?: number;
|
||||||
|
width?: number;
|
||||||
|
innerHeight?: number;
|
||||||
|
clientHeight?: number;
|
||||||
|
}) {
|
||||||
|
const el = (offsetHeight = 36) => ({
|
||||||
|
style: {} as Record<string, string>,
|
||||||
|
offsetHeight,
|
||||||
|
classList: { contains: () => true },
|
||||||
|
});
|
||||||
|
// .app is sized to the visual viewport (--app-height), which is what its fixed
|
||||||
|
// children are placed against once it carries a transform.
|
||||||
|
const nodes: Record<string, any> = {
|
||||||
|
'.app': el(height),
|
||||||
|
'.toolbar': el(),
|
||||||
|
'.main': el(),
|
||||||
|
'.keyboard-accessory-bar': el(),
|
||||||
|
};
|
||||||
|
const cjk = { ...el(), id: 'cjkInput' };
|
||||||
|
const context = vm.createContext({
|
||||||
|
console,
|
||||||
|
navigator: { userAgent: 'test', maxTouchPoints: 1 },
|
||||||
|
window: {
|
||||||
|
addEventListener: () => {},
|
||||||
|
matchMedia: () => ({ matches: false }),
|
||||||
|
scrollTo: () => {},
|
||||||
|
innerHeight,
|
||||||
|
innerWidth: width, // MobileDetection (defined in the module) reads this
|
||||||
|
visualViewport: { offsetTop, height },
|
||||||
|
},
|
||||||
|
document: {
|
||||||
|
body: { classList: { add: () => {}, remove: () => {} } },
|
||||||
|
documentElement: { clientHeight },
|
||||||
|
addEventListener: () => {},
|
||||||
|
activeElement: focused === 'cjkInput' ? cjk : { id: focused },
|
||||||
|
getElementById: (id: string) => (id === 'cjkInput' ? cjk : null),
|
||||||
|
querySelector: (sel: string) => nodes[sel] || null,
|
||||||
|
},
|
||||||
|
setTimeout: () => 1,
|
||||||
|
clearTimeout: () => {},
|
||||||
|
});
|
||||||
|
vm.runInContext(`${SOURCE}\nglobalThis.__KH = KeyboardHandler;`, context, { filename: 'mobile-handlers.js' });
|
||||||
|
const kh = (context as { __KH: any }).__KH;
|
||||||
|
kh.keyboardVisible = true;
|
||||||
|
kh.initialViewportHeight = 744;
|
||||||
|
return { kh, nodes, cjk };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('KeyboardHandler follows the visual-viewport pan on phones', () => {
|
||||||
|
it('moves the app down by the pan and lifts nothing more (measured Android case)', () => {
|
||||||
|
const { kh, nodes, cjk } = loadLayout({ offsetTop: 285 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('translateY(285px)');
|
||||||
|
// .app bottom = 285 + 458 = 743, visual bottom = 743: the bars already sit on it.
|
||||||
|
expect(nodes['.toolbar'].style.transform).toBe('');
|
||||||
|
expect(nodes['.keyboard-accessory-bar'].style.transform).toBe('');
|
||||||
|
expect(cjk.style.transform).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not lift the bars twice on a partial pan', () => {
|
||||||
|
// Mid-animation: offsetTop 100 in a 744 layout. Lifting by the layout gap (186px)
|
||||||
|
// inside the shifted .app would float the bars 186px above the keyboard.
|
||||||
|
const { kh, nodes, cjk } = loadLayout({ offsetTop: 100 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('translateY(100px)');
|
||||||
|
expect(nodes['.toolbar'].style.transform).toBe('');
|
||||||
|
expect(nodes['.keyboard-accessory-bar'].style.transform).toBe('');
|
||||||
|
expect(cjk.style.transform).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('keeps the old lift when there is no pan', () => {
|
||||||
|
const { kh, nodes } = loadLayout({ offsetTop: 0 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('');
|
||||||
|
expect(nodes['.toolbar'].style.transform).toBe('translateY(-286px)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('follows a pan whatever has focus, so a focus change cannot drop the shift', () => {
|
||||||
|
const { kh, nodes } = loadLayout({ focused: 'someOtherField', offsetTop: 285 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('translateY(285px)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('never shifts the app outside the phone layout (tablet landscape)', () => {
|
||||||
|
const { kh, nodes } = loadLayout({ offsetTop: 285, width: 1024 });
|
||||||
|
nodes['.app'].style.transform = 'translateY(285px)'; // left over from portrait
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lifts the bars when iOS reports innerHeight as the shrunk visual height', () => {
|
||||||
|
// Measured on an iPhone, first keyboard open: innerHeight 323 = visual height,
|
||||||
|
// documentElement.clientHeight 640. Lifting by innerHeight - visual bottom gave 0.
|
||||||
|
const { kh, nodes, cjk } = loadLayout({ offsetTop: 0, height: 323, innerHeight: 323, clientHeight: 640 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
expect(nodes['.toolbar'].style.transform).toBe('translateY(-317px)');
|
||||||
|
expect(nodes['.keyboard-accessory-bar'].style.transform).toBe('translateY(-317px)');
|
||||||
|
expect(cjk.style.transform).toBe('translateY(-317px)');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('clears the shift when the layout resets', () => {
|
||||||
|
const { kh, nodes } = loadLayout({ offsetTop: 285 });
|
||||||
|
kh.updateLayoutForKeyboard();
|
||||||
|
kh.resetLayout();
|
||||||
|
expect(nodes['.app'].style.transform).toBe('');
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -139,6 +139,28 @@ describe('terminal touch tap mouse guard', () => {
|
|||||||
expect(app._isMobileTerminalInputFocused()).toBe(true);
|
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', () => {
|
it('routes a readback row to the TUI while keeping the prompt row as keyboard input', () => {
|
||||||
const { app } = loadTerminalUiHarness();
|
const { app } = loadTerminalUiHarness();
|
||||||
app.activeSessionId = 'sess-1';
|
app.activeSessionId = 'sess-1';
|
||||||
@@ -967,9 +989,27 @@ describe('terminal link tap', () => {
|
|||||||
app._isOutsideWorktreePath = () => false;
|
app._isOutsideWorktreePath = () => false;
|
||||||
windowRef.open = vi.fn();
|
windowRef.open = vi.fn();
|
||||||
app.registerFilePathLinkProvider();
|
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', () => {
|
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 line = 'Login at https://claude.ai/oauth/authorize?code=true&client_id=abc to finish';
|
||||||
const { app, windowRef } = linkHarness([line, '', '❯ ']);
|
const { app, windowRef } = linkHarness([line, '', '❯ ']);
|
||||||
|
|||||||
Reference in new issue
Block a user