Skip to content

fix(tui): keep the Mini draft caret when closing the command palette - #63260

Merged
jlongster merged 1 commit into
devfrom
fix/mini-palette-caret
Nov 12, 2026
Merged

jlongster merged 1 commit into
devfrom
fix/mini-palette-caret

Conversation

@jlongster

@jlongster jlongster commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Issue for this PR

Type paper in Mini and press Left three times: pa│per. Press Ctrl+P, Escape, then type Z. The draft survives on both revisions. On dev, the caret jumps from offset 2 to 5 and the next key produces paperZ. With the fix, Escape restores offset 2 and the next key produces paZper.

Type of change

  • Bug fix

What does this PR do?

Save the native textarea offset as the composer unbinds, then restore the draft and offset together when it binds again. The existing editor measurement and clamping still apply when restoring a replacement draft.

How did you verify your code works?

Ran the same nine-case Statecheck property against dev (1af61ee45c41713c47fd42e80ff775e5d060c06b) and this fix (da22bf16cc4521cad62a1f4a0b76a82d6ded8a02). Three cases failed on dev: the middle of paper, the middle of a wide-character multiline draft, and the start of grid. All nine passed on the fix. The original red\nblue end-of-draft example already passes on dev. Controls also cover direct typing and selecting Show status and New session, including their callbacks.

Property, replay bundle, and full receipts

The fixture mounts the production Mini footer in OpenTUI 0.8.4’s native 64×16 test renderer under Bun 1.4.2. Each case drives the keymap and reads the focused editor and rendered frames. The host guard deferred the broader suite because a delegated cgroup was unavailable. Scope: footer only.

Replay bundle with property and full receipts · Dev trace · Fix trace · Trace viewer

Extract the bundle, then run from its root on Linux with Bun, unshare -n, and installed checkouts of the two SHAs above:

set -eo pipefail
case_dir=overnight/tui-draft-dev
OPENCODE_REPO="$BASE" bash "$case_dir/run.sh" | cmp "$case_dir/red.json" -
OPENCODE_REPO="$FIX" bash "$case_dir/run.sh" | cmp "$case_dir/green.json" -

Screenshots / recordings

Before (dev 1af61ee45c) and after (fix da22bf16cc), side by side

Real opencode mini, same keys on both revisions: type paper, ← ×3, Ctrl+P, Escape, Z. Left: dev ends with paperZ. Right: the fix keeps the caret and ends with paZper. MP4

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

User decisions:
- Correct the existing Mini draft against current dev.
- Keep the upstream diff focused on production code.
@jlongster
jlongster changed the base branch from v2 to dev November 11, 2026 05:56
@jlongster
jlongster force-pushed the fix/mini-palette-caret branch from 70501b4 to da22bf1 Compare November 11, 2026 05:56
@jlongster
jlongster marked this pull request as ready for review November 12, 2026 16:44
@jlongster
jlongster enabled auto-merge (squash) November 12, 2026 16:45

@opencodejr opencodejr Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reproduced the bug on dev and the fix works. opencode-drive can't open Mini, so I mounted the real footer in OpenTUI's test renderer and ran the PR's steps on both revisions: type a draft, move the caret left, press Ctrl+P, then Escape, then Z.

  • dev: paper and grid both lose the caret position (paperZ, gridZ).
  • This PR: the caret stays put (paZper, Zgrid).
  • End-of-draft red\nblue: passes on both, as the description says.

All packages/tui/test/mini tests pass and tsc -b is clean.

Removing the restore that ran when the view changed back to prompt looks right: the composer only renders in that view, so the restore on rebind already covers it. When the draft is replaced while the composer is closed, the caret still goes to the end, and resetDraft puts it back at 0.

Public API is unchanged; this is internal TUI state.

No blocking concerns.

@jlongster
jlongster merged commit 32a00c9 into dev Nov 12, 2026
32 checks passed
@jlongster
jlongster deleted the fix/mini-palette-caret branch November 12, 2026 16:49
@jlongster

Copy link
Copy Markdown
Contributor Author

Thanks for checking this on both revisions. I replaced the reconstructed frames in the description with a real side-by-side recording of opencode mini at 1af61ee45c and da22bf16cc (same keys on both: paper, ← ×3, Ctrl+P, Escape, Z).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant