mirror of
https://github.com/Ark0N/Codeman.git
synced 2026-11-20 04:59:34 +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
+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)
|
||||
|
||||
**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.
|
||||
|
||||
|
||||
@@ -435,21 +435,44 @@ const KeyboardHandler = {
|
||||
// BEHIND the keyboard with its own search box out of sight.
|
||||
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) {
|
||||
// Phones/small tablets: toolbar and accessory bar are position:fixed
|
||||
// via CSS. Use translateY to lift them above the keyboard.
|
||||
const toolbar = document.querySelector('.toolbar');
|
||||
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) {
|
||||
toolbar.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
||||
toolbar.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||
}
|
||||
if (accessoryBar) {
|
||||
accessoryBar.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
||||
accessoryBar.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||
}
|
||||
if (caseSheet) {
|
||||
caseSheet.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
||||
@@ -476,11 +499,8 @@ const KeyboardHandler = {
|
||||
// CJK textarea positioning (always position:fixed on touch devices).
|
||||
if (cjkInput?.classList.contains('cjk-input-visible') && keyboardHeight > 0) {
|
||||
if (isSmallMedium) {
|
||||
// Phones: use translateY like toolbar/accessory bar.
|
||||
const layoutHeight = window.innerHeight;
|
||||
const visualBottom = window.visualViewport.offsetTop + window.visualViewport.height;
|
||||
const keyboardOffset = Math.max(0, layoutHeight - visualBottom);
|
||||
cjkInput.style.transform = keyboardOffset > 0 ? `translateY(${-keyboardOffset}px)` : '';
|
||||
// Phones: use translateY like toolbar/accessory bar (it sits inside .app too).
|
||||
cjkInput.style.transform = insideLift > 0 ? `translateY(${-insideLift}px)` : '';
|
||||
cjkInput.style.bottom = '';
|
||||
} else {
|
||||
// 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
|
||||
// next open slides in already displaced.
|
||||
const caseSheet = document.querySelector('.mobile-case-picker-sheet');
|
||||
const appEl = document.querySelector('.app');
|
||||
|
||||
if (appEl) {
|
||||
appEl.style.transform = '';
|
||||
}
|
||||
if (toolbar) {
|
||||
toolbar.style.transform = '';
|
||||
}
|
||||
@@ -733,6 +757,11 @@ const KeyboardHandler = {
|
||||
if (el.closest('.xterm') || el.closest('.terminal-container')) {
|
||||
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();
|
||||
// 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
|
||||
// the keyboard unreachable after every tab switch.
|
||||
ev.preventDefault();
|
||||
this._blurMobileTerminalInput();
|
||||
if (this._contentTouchStartBlurs()) this._blurMobileTerminalInput();
|
||||
}
|
||||
// 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.
|
||||
@@ -5701,6 +5701,19 @@ Object.assign(CodemanApp.prototype, {
|
||||
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() {
|
||||
const active = document.activeElement;
|
||||
if (
|
||||
@@ -5899,6 +5912,9 @@ Object.assign(CodemanApp.prototype, {
|
||||
) {
|
||||
// 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.
|
||||
// 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';
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user