Skip to content

fix(terminal): the key bar's keyboard control acts on its tap's word - #2333

Merged
devswha merged 11 commits into
devswha:mainfrom
IdrisGit:fix/keyboard-intent-store
Oct 29, 2026
Merged

devswha merged 11 commits into
devswha:mainfrom
IdrisGit:fix/keyboard-intent-store

Conversation

@IdrisGit

Copy link
Copy Markdown
Contributor

Closes the phone keyboard-control bug that #1973's control hid underneath: the control is there, but a tap's meaning could not be trusted.

Problem

On a phone, the key bar over the keyboard has an Input line switch, Paste and a Show keyboard / Hide keyboard control (#1046, #1973). Two things went wrong with it:

  • The keyboard control fights itself. Tapping Hide makes the keyboard open; the open control shows armed over a keyboard that is visibly up; and tapping several times in a row makes the keyboard open and close in bursts, the label and the glyph flipping without ever matching the keyboard for long.
  • After Android's back gesture (the keyboard put away, the field left focused), tapping the control does nothing.

Switching Input line / direct typing rides the same keyboard: the switch alone raises it and puts it away, so changing where you type looks like a broken keyboard button.

Cause

The control had no state of its own. Its label, glyph, aria-pressed and the action the tap took were each re-read, at tap time, from data-keyboard — a visual-viewport measurement that flips in the middle of the keyboard's own slide (Chromium's geometry overshoots the resting height and no API says when it settled). A tap therefore meant whichever side of the animation the last measurement happened to land on, and a measurement blind to a zoomed page or a floating keyboard kept the control lying for good.

Change

  • New src/lib/keyboardControl.ts: a small store that keeps the tap's word (last tap wins) until the keyboard measurement confirms it and holds still (120 ms, past the overshoot) or a 700 ms settle window runs out. A composition or a pending commit refuses the tap before any state changes, and a tap this pane has no target for records nothing. One derivation (view) is what the label, the glyph, aria-pressed and the next tap's action all read, so the control can never say one thing and do another.
  • lib/viewport.ts feeds each measurement to the store; data-keyboard's meaning for every other reader (shell height, grid hold, CSS) is untouched.
  • toggleKeyboard now only performs the focus and blur, inside the tap's own gesture: Show blur-and-refocuses an already focused field, which is what re-raises the keyboard a back gesture put away, and Hide's blur leaving no field focused anywhere reads as the keyboard going where the measurement is blind.
  • The Input line switch is no keyboard gesture: direct to line hands the grid's keyboard to the input line, focus and all, in a layout effect before paint, gated on touch.

What it improves

  • Hide puts the keyboard away the first time, every time, and the control always says what its next tap will do — the armed state can no longer disagree with the keyboard.
  • Rapid taps end in the last tap's state instead of an open/close storm.
  • The keyboard comes back after the back gesture.
  • Switching input modes keeps the keyboard up where you had it, instead of raising and dismissing it by side effect.

## Problem

On a phone, the key bar's Show/Hide keyboard control re-decided the
tap's action at tap time from data-keyboard, a visual-viewport
measurement that flips mid-slide (Chromium's keyboard geometry
overshoots, and nothing says when it settled). Hide then ran as Show,
the open control sat armed over a keyboard visibly up, rapid taps made
the keyboard open and close in bursts, and after Android's back gesture
(field left focused, keyboard down) Show focused an already focused
field, which raises nothing. The Input line switch rode the same
keyboard: switching input mode alone raised and put it away.

## Change

- New src/lib/keyboardControl.ts: the tap's word is kept as intent
  until the measurement confirms it (held still 120 ms, past the
  overshoot) or the 700 ms settle window runs out; last tap wins, a
  composition or pending commit refuses before any state changes, and
  a tap this pane has no target for records nothing. One derivation,
  keyboardControlView, is what the label, glyph, aria-pressed and the
  next tap's action all read.
- viewport.ts feeds each sync's measurement to the store; data-keyboard's
  meaning for every other reader is untouched.
- toggleKeyboard now only performs the focus and blur, inside the tap's
  gesture: an already focused field is blurred and refocused (the
  back gesture's dead tap), and a blur that leaves no field focused
  anywhere is the keyboard going, which a blind measurement (a zoomed
  page, a floating keyboard) cannot see.
- The mode switch is no keyboard gesture: direct to line hands the
  grid's keyboard to the input line, focus and all, in a layout effect
  before paint, gated on touch (useTerminalSends, TerminalInput's
  focus() handle).

Unit tests drive the store on a hand clock; the demo regression is
updated to the new contract, and the back-gesture branch, the mode
handoff and an already focused Show with DECSET 1004 on are pinned.
@coderabbitai

coderabbitai Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: c32bded
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 87ec76fc-6bf0-40e9-8149-81c88bf6f095

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: devswha/ovis
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 99147f8
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 659f2f9a-1bd9-4a42-b18c-a78d952a54e1
Commits

Reviewing files that changed from the base of the PR and between 99147f8 and 1ba7f0b.

Files selected for processing: 12
  • DESIGN.md
  • changelog.d/keyboard-control-intent.md
  • scripts/terminal-keyboard-demo-regression.ts
  • src/components/KeyBar.tsx
  • src/components/PaneTerminal.tsx
  • src/components/TerminalInput.tsx
  • src/lib/keyboard.test.ts
  • src/lib/keyboard.ts
  • src/lib/keyboardControl.test.ts
  • src/lib/keyboardControl.ts
  • src/lib/useTerminalSends.ts
  • src/lib/viewport.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

📝 Summary

Summary by CodeRabbit

  • Bug Fixes
    • The touch keyboard control now immediately reflects the requested Show or Hide action and stays consistent while keyboard visibility is confirmed or settles.
    • Tapping Show can raise the keyboard again when the input is already focused.
    • Switching from the key-bar input line to direct typing preserves the keyboard, while explicit input-mode changes continue to control keyboard visibility.
    • Keyboard actions are ignored during active text composition.

The keyboard control now reflects tap intent while viewport measurements settle. Focus handling supports showing the keyboard on an already-focused field and switching between the input line and direct typing. Tests and documentation cover these behaviors.

Changes: Touch keyboard control and input handoff

Layer / File(s) Summary
Keyboard intent state and viewport measurement
src/lib/keyboardControl.ts, src/lib/keyboard.ts, src/lib/viewport.ts, src/lib/keyboardControl.test.ts, src/lib/keyboard.test.ts
A new store tracks keyboard-control intent, measured visibility, and settle timing. Viewport measurements feed the store, and shared typing-field detection replaces the prior local predicate. Tests cover state transitions, timers, and subscriptions; tests for the removed helpers are deleted.
Key-bar actions, focus handoff, and regression coverage
src/components/KeyBar.tsx, src/components/PaneTerminal.tsx, src/components/TerminalInput.tsx, src/lib/useTerminalSends.ts, scripts/terminal-keyboard-demo-regression.ts, DESIGN.md, changelog.d/keyboard-control-intent.md
The key bar displays the next action from the store. Pane actions focus or blur input fields, and the terminal input handle exposes focus(): boolean. Input-mode handoffs update focus. Regression checks and documentation cover immediate control state, focus handoffs, and cases where keyboard visibility is not measured.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Bug fix

Suggested reviewers: devswha

Merge Risk: Minimal · previous review 1ba7f

The change appears mergeable after normal checks; the supplied evidence does not establish an issue requiring a fix before merge.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: the key bar keyboard control now follows the tap's intended action.
Description check Passed The description clearly explains the problem, cause, implementation, and resulting behavior. It is on-topic and mostly complete, although it does not include the template's exact headings or validatio…
Docstring Coverage Passed Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentati…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the problem, cause, implementation, and resulting behavior. It is on-topic and mostly complete, although it does not include the template's exact headings or validation results.

Full details: Docstring Coverage

Explanation

Docstring coverage is 87.50% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 8 functions across 10 files. (2 skipped: 2 unsupported.)

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

… pane

Review fixes on devswha#2333:
- A tap's word is confirmed only by measurements taken after that tap:
  a reversal Show during the last Hide's animation is no longer cleared
  by the old, still-occluding value (agreedAt replaces changedAt).
- The word is the tapping pane's own: another pane's control reads the
  measurement, so its Show acts while a tap is in flight elsewhere
  (KeyBar keyboardOwner, PaneTerminal useId + paneStorageId).
- The Input line switch leaves the keyboard as the control says it is:
  up, the new mode's field takes it; down (including Android's back
  gesture with a field still focused), the switch focuses nothing.
- The keyboard demo regression: read the tap's word after React commits
  it, keep the grid under a keyboard across a switch (devswha#1045), and hold
  the clock through a pane switch while a sibling's tap is in flight.
- A tap whose measured value already agreed before it (a reversal during
  the last animation) is confirmed only after the measurement moves:
  an unchanged boolean is no proof the keyboard stopped moving.
- A hold ends at its quiet window by a timer, without a further
  viewport event, so a Back dismissal after one up reads down (and the
  mode switch no longer raises it).
- A pane that stops being the selected, shown one gives up its tap in
  flight (keyboardControl.release), so coming back it reads the
  measurement instead of an unusable Hide.
- Demo regression: the keyboard-up switch flushes deferred work before
  comparing the grid and checks no resize; the sibling check asserts
  the tapped pane's word is in flight under the paused clock.
- DESIGN and the changelog name what the switch does where the
  measurement is blind (floating keyboard, zoomed page).
…swha#2333 review round 3)

A Show tapped after Hide's blur but before the viewport's deferred
focusout sync saw the blur's local "down" and was not marked stale, so
the old animation's unchanged "up" confirmed it. The store now keeps the
last value the viewport measured (observed) apart from the local hidden
confirmation, and a tap is stale against that.

Also rewords the demo's sibling assertion to what it checks now that a
pane left mid-tap gives its word up.
@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Thank you @IdrisGit — splitting the tap's word from the keyboard's measured value is the right shape, and the store made the fixes below small. Per our usual flow for external PRs, we fixed the review findings on your branch ourselves (maintainer edits, merged main in, no force-push).

What we changed

  • The tap's word is confirmed only by geometry measured after the tap (src/lib/keyboardControl.ts). A reversal tapped during the previous Hide animation could be "confirmed" by that animation's still-up value, flipping the label against the last tap. A tap now resets the hold, a tap whose value already agreed beforehand (stale, judged against the viewport's own last value, not the blur's local "down") waits for the measurement to move, and a quiet-window timer confirms a hold even when no further viewport event arrives.
  • The word belongs to the pane that tapped. Each control reads view(owner) (owner = useId + paneStorageId), so another pane shows and does what it can itself; a pane left while its tap is in flight gives the word up (keyboardControl.release), so coming back it never shows an unusable Hide.
  • The Input line / direct typing switch leaves the keyboard as it is (src/lib/useTerminalSends.ts). With the keyboard up (or on its way up from this pane's tap), the new mode's field takes it; with it down — including Android's back-gesture state, where the field keeps the focus — the switch focuses nothing. Where the page cannot measure a keyboard (iPad floating keyboard, zoomed page) it counts as down; DESIGN.md and the changelog now say so.
  • Keyboard demo regression: new keyboard-down switch checks in both directions, a frozen-clock check that a sibling pane is not held by another pane's tap, and fixes for three assertions that could not pass as written (the tap's word is read after React commits it; a switch under a keyboard keeps the grid, Terminal (phone): opening the soft keyboard resizes the shared pty #1045, and sends no resize; the clock is held through the pane switch).

Evidence

  • Fail-first unit tests in keyboardControl.test.ts for each finding (each fails on the previous head, all 36 pass now); the demo's new switch and sibling checks fail on 1ba7f0b and pass now.
  • Real keyboards, before (1ba7f0b) / after:
    • Android 16 emulator, Chrome 133 + Gboard, real taps and the Back gesture: Show → up, Back → down with the field focused, Show → up again, both switches with the keyboard down → stays down, rapid Hide→Show → ends up, switch with the keyboard up → the line takes it. On 1ba7f0b both keyboard-down switches raised Gboard.
    • iOS 27 Simulator, Safari, software keyboard: Show/Hide follow the keyboard; line → direct with the keyboard down raised it on 1ba7f0b and keeps it down now.
  • bun run check fast green on the merged head; terminal keyboard demo regression green.

Reviews (CodeRabbit had already reviewed the first head)

  • Merge-pass review of 1ba7f0b: HIGH stale-geometry confirmation, MEDIUM page-global intent, MEDIUM switch still moving the keyboard → all fixed above.
  • omo code reviewer: APPROVE (MEDIUM: docs overclaimed for blind measurement → qualified; LOWs: demo assertion strength → fixed).
  • Codex (Sol 6.1, xhigh), three rounds: round 1 HIGH (unchanged "up" is no proof the keyboard stopped) + 2 MEDIUM (hidden pane resurrecting a pending Show; a Show confirmed by one "up" staying pending through Back) → fixed; round 2 HIGH (reversal before the deferred focusout sync) → fixed with observed; round 3: APPROVE.

Not changed (LOW, noted): a quick Show→Hide can read "Hide keyboard" briefly when a late "up" arrives after two quiet "down" readings; not reproduced on a device and not a regression.

… not fire()

fire() also ran the 700 ms settle fallback, which cancels the quiet
timer, so the two quiet-window confirmations passed without it. due()
runs only the timers whose deadline has come; both tests now fail when
the quiet-window timer is removed.
…evswha#2333

Direct to line with the keyboard up now hands the focus to the input
line instead of blurring the grid. The check's next step (a smaller
viewport with no field focused is not a keyboard) assumed that blur:
assert the handoff, then blur before it.
@devswha

devswha commented Oct 29, 2026

Copy link
Copy Markdown
Owner

Merging 33f66b6, thank you @IdrisGit! On a phone, the key bar's Show/Hide keyboard control now acts on the user's tap instead of re-reading mid-slide viewport geometry: the label, glyph and aria-pressed follow the last tap, rapid taps settle on the last one without open/close bursts, a tap works again after Android's back gesture, and switching between the input line and direct typing no longer raises or drops the keyboard. Strict external review by the merge pass; per the maintainer's rule lane fix-2333 fixed the findings on the branch with maintainer edits: a stale animation could confirm a reversal tap (HIGH), the pending intent was page-wide instead of per pane, the mode switch still moved the keyboard in two cases, and two tests fired the fallback timer instead of proving the quiet window. The mobile viewport regression now asserts the input-line handoff (the intended behaviour) and blurs before its no-keyboard step. 36 tests, typecheck and the phone keyboard demo pass; Android emulator and iOS Simulator before/after are in the PR. The paused lane feat-1531 (phone keyboard-mode button) overlaps in KeyBar and PaneTerminal imports and will rebase on this.

@devswha
devswha merged commit 2cfbed0 into devswha:main Oct 29, 2026
12 checks passed
@devswha devswha mentioned this pull request Oct 30, 2026
devswha added a commit that referenced this pull request Oct 30, 2026
## Release 0.4.21

The release PR, prepared by step 1 of
[docs/development.md#releasing](https://github.com/devswha/ovis/blob/main/docs/development.md#releasing),
now re-folded on main `1ef6ea329108a0985b823e8235b03daddcd0a5f4` after
the owner held 0.4.21 for more work. The merge pass reported the 0.4.21
queue empty.

**Do not merge yet:** the owner judges the final build before release.
No tag and no Release run from this PR's author.

- **Version:** `version` is 0.4.21 in `package.json` and
`herdr-plugin.toml`.
- **Changelog:** `bun scripts/changelog-fold.ts 0.4.21 2026-10-30`
folded 63 fragments into the 2026-10-30 section of `CHANGELOG.md` (71
entries), linked their PRs and deleted the fragments; `changelog.d`
holds only `README.md`.
- `by @login` on every outside contributor's PR link: #2361 @eddieparc,
#2333 @IdrisGit, #2355 @imurfutur3, #2341 @sulthonzh, #2359 @YuuuXie,
#2377 @IdrisGit, #2269 @CharleoYang, #2405 @jpcarranza94, #2414
@homebodify, #2417 @cheol-95, #2418 @eddieparc, #2435 @cheol-95.
- Two outside PRs had no fragment and got an entry by hand: #2341
(OpenCode background commands, Added) and #2359 (installer test timing,
Maintenance).
- Issue reporters are credited in their entries: @blaker3115-Agri
(#1488), @Hyd3-14 (#2026), @osamahbeig (#2343), @Shunamxiao (#2329),
@matiemer (#2362), @kilhyeonjun (#2344), @eddieparc (#2360), @Ploppy3
(#2236), @sulthonzh (#2340), @WOULDU-pres (#2056), @odfalik (#2038),
@aNNdii (#511), @Noobear (#2281, fixed by #2424); #2435 fixes
@cheol-95's own #2434.
- Two fragments ran past the changelog's width (#2418, #2269); their
entries are re-wrapped, words unchanged. #2382's entry reads "OpenCode's
installer puts its folder first" (reviewed earlier on this PR).
- Maintainer PRs without a fragment and without a user-facing change
have no entry: #2353 (check tool), #2371 (guide docs), #2396 and #2397
(tests), #2403 and #2433 (server and client transport seams, no
behaviour change), #2437 (test-only fix for #2435's check). #2438's own
entry (the sidebar selection marked by its fill again) is dropped: the
stroke #2352 added never shipped, so users see no change; #2352's entry
keeps only the Windows high-contrast Highlight bar.
- **Release summaries:** en, ko, ja and zh each have 5 new, 5 improved
and 5 fixed lines. Since the first review: New lists the in-browser
Claude Code / Codex sign-in (#2428) in place of the tab/workspace
shortcut line; Improved lists Settings → Agents (#2427) in place of the
sidebar fold line; Fixed lists the Codex wrong-session fix (#2426,
#2430) in place of the phone screenshot paste line. The Artifacts and
Claude status-line lines keep their reviewed wording (turned on in
Settings). Not in 0.4.21: #2420 (Codex chat behind Kiro), #2065 (Portal
sign-in) and #2436 (relay foundations) stay open for a later release.
- **Remote bundle:** `REMOTE_BUNDLE_VERSION` rises from 39 to 40 because
the bundle inputs (`server/`, `shared/`, `patches/`) changed since
remote-v39. After merge: push `remote-v40` on the merged commit and wait
for the Remote PC bundles workflow before running Release.
- **iOS:** `CURRENT_PROJECT_VERSION` stays 3 (#2370 changed
`Info.plist`; build 3 is not known to be uploaded yet).

## Validation

- `bun scripts/release-guards.ts --base v0.4.20`: "Release 0.4.21:
remote bundle, telemetry Worker and release metadata are in order."
- `dori heavy … bun run check fast` on this branch: workflow syntax,
generated types and themes, typecheck, build, unit tests all ok. Unit:
9166 pass, 0 fail, 36 skip in 591 files.
- Every PR in `v0.4.20..main` was pre-run for the owner's hands-on guide
on isolated copies (own herdr session, fresh state, never the owner's
live session). Items that need a real device (iPhone tap dictation
#2370, dictation keyboards #2386, the installed desktop app's title-bar
overlay #2381) are left for the owner's final check.

This is a release-metadata PR: it changes no code path. Per the release
steps, merge it after CI and the owner's go, then push `remote-v40`,
wait for its bundles, and run Release with `0.4.21`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants