Skip to content

fix(switch): eliminate the alt-x picker cursor flash - #3268

Merged
max-sixty merged 1 commit into
mainfrom
fix-picker-altx-cursor-flash
Jun 27, 2026
Merged

max-sixty merged 1 commit into
mainfrom
fix-picker-altx-cursor-flash

Conversation

@max-sixty

@max-sixty max-sixty commented Jun 27, 2026 •

Copy link
Copy Markdown
Owner

What

Removing a row in the wt switch picker with alt-x flashed the > pointer to the top of the list for a frame before it settled on the right row. This eliminates that flash.

Root cause

The flash was structural to skim's reload, not a lagging reposition. alt-x was bound to reload(remove {}), and skim's handle_reload clears the item pool and restarts the matcher before the new rows stream in — so the matcher runs once against the empty pool, Replaces item_list with nothing, and skim's render clamp (items.is_empty() → current = 0) resets the cursor to the top. A reposition Custom action then snapped it back, but the reset frame was already painted. (no_clear_if_empty doesn't help: its protective "keep stale rows" branch is gated on skim's interactive mode, which the picker doesn't use — verified with a steady-state A/B.)

The fix

Replace the reload-based removal with a synchronous in-place pool resync. alt-x is now a single Custom keybinding callback that runs the removal dispatch (AltXRemover::apply) and rebuilds skim's pool from the mutated row list (resync_pool) on the same event-loop tick. The pool is filled before the matcher runs, so the matcher only ever sees the post-removal list — never empty — and current is preserved (clamped to the shrunk list). The row that slides into the removed slot lands under the cursor for free, with no flash, under a fuzzy filter too.

This lets the whole reposition apparatus go — reposition_cursor_action, send_reposition, the drop_landing neighbour capture, the settle counters — for a net deletion. The removal dispatch moved off the collector into a Send AltXRemover (skim requires the keybinding callback to be Send, so it can't carry the collector's Rc<PipelineFactory>); PickerCollector now only serves the alt-r refresh. Keep/morph repaint in place; the rare failed-removal restore queues a resync_pool_action.

Two follow-on fixes surfaced while validating

Last-row preview. skim auto-repaints the preview across the matcher's Replace only when the selected row's text changes — which a last-row drop doesn't produce (current goes briefly out of range, then clamps onto the new last row with no text change). The pane kept showing the removed row's preview; run_preview_when_settled restores the missing repaint. (Found in review.)

--prs streaming order. The alt-x rework tipped a pre-existing microsecond race: on_skeleton woke the --prs thread (grid_slot.set) before sending the skeleton batch, so with a fast forge call the PR rows could reach skim's channel first and a PR row would take the reserved header slot (header_lines(1)), displacing the header — the cursor then couldn't reach the PR row. That's what made test_switch_picker_preview_auto_refreshes_when_compute_lands a long-standing flake. Fixed deterministically: the --prs thread is now woken only after the skeleton is sent, so PR rows always append after it.

Navigating the diff

src/commands/picker/mod.rs (the alt-x rework, a net deletion), progressive_handler.rs (the one-statement --prs ordering fix), and tests/integration_tests/switch_picker.rs (new tests).

Testing

The eight existing alt-x cursor PTY tests pass unchanged; removal unit tests drive AltXRemover::apply directly. Added PTY tests for the last-row preview refresh and the failed-removal restore, and a unit test for the unmorphable-row drop fallback. Verified frame-by-frame under tmux (drop, morph, keep, filtered drop, last-row drop) that the pointer never jumps to the top row. The full pre-merge gate passes locally (4255 tests).

This was written by Claude Code on behalf of max

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed this as a refactor of the alt-x removal plumbing. The change is rendering-only — it swaps reload-based removal for an in-place resync_pool and drops the reposition machinery — and I traced that the data-safety semantics survive intact: the row is still dropped optimistically, do_removal runs on the background thread, and removal_target_still_present → restore_failed_removal still puts the row back when the worktree unexpectedly survives. No new force-delete path; the deletion_mode.is_force() / do_removal dispatch is unchanged.

I confirmed the load-bearing API call against skim 4.8.0: restart_matcher(true) takes the force branch (MergeStrategy::Replace + item_pool.reset()) and never resets item_list.current (only the min_query_length short-circuit does), so the "cursor holds its slot" claim holds — the empty-pool transient that reset current = 0 is what the old reload path hit.

No blocking findings. Since this sits on the worktree/branch deletion surface, I'm leaving the merge call to you rather than auto-approving.

One non-blocking note: RemovalEffect::Dropped always queues run_preview_when_settled, but per its own docstring only the last-row drop actually needs it — a middle-row drop already gets skim's on_selection_changed RunPreview, so it ends up firing a redundant (harmless) second RunPreview. Fine as-is; just flagging that the always-queue is slightly broader than the comment's "covers the last-row gap" framing suggests.

Comment on lines +714 to +718
if let Some(diagnostic) = e.render_diagnostic() {
let mut stashed = self.stashed_warnings.lock().unwrap();
if !stashed.contains(&diagnostic) {
stashed.push(diagnostic);
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Non-blocking, carried over from the pre-refactor code: this render_diagnostic() arm has no fallback, so it diverges from the comment just above it. wt remove itself prints e.render_diagnostic().unwrap_or_else(|| e.to_string()) (remove.rs:43), as do for_each.rs, relocate.rs, and config/show.rs. Here, an error whose chain carries no typed Diagnostic makes render_diagnostic() return None, so nothing is stashed — exactly the "silent dead keypress" the comment says it's avoiding, and not the same output wt remove would print. The common cases (main worktree, dirty, lock) are typed so the gap is narrow, but the one-line fix realigns it with the other four call sites and the trait's own doc-example:

Suggested change
if let Some(diagnostic) = e.render_diagnostic() {
let mut stashed = self.stashed_warnings.lock().unwrap();
if !stashed.contains(&diagnostic) {
stashed.push(diagnostic);
}
let diagnostic = e.render_diagnostic().unwrap_or_else(|| e.to_string());
let mut stashed = self.stashed_warnings.lock().unwrap();
if !stashed.contains(&diagnostic) {
stashed.push(diagnostic);
}

@worktrunk-bot worktrunk-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The incremental change since my last review checks out. I re-verified the load-bearing claim against skim 4.8.0: handle_action sends the callback's returned events to the channel before the Event::Render it appends (src/tui/app.rs, the Event::Action arm — for evt in events { event_tx.try_send(evt) } then try_send(Event::Render)), and the channel is FIFO, so the queued resync_pool_action rebuilds the pool before the first repaint — equivalent to the old inline resync_pool, no flash regression. The --prs ordering fix in progressive_handler.rs is sound too: grid is moved only at the deferred grid_slot.set, so computing shown_branches early and waking the thread after the skeleton send is safe.

One small doc-accuracy drift introduced by this commit (non-blocking).

Still on the worktree/branch deletion surface, so leaving the merge call to you.

// the matcher re-filters it in place — the cursor holds its index and
// the row that slid up lands under it (no reset, no flash). skim
// processes a callback's returned events (then a Render) in order, so
// the queued resync runs before any repaint — same effect as an inline

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This commit moved the drop-path resync from an inline resync_pool(app, …) to a queued resync_pool_action, and updated this inline comment to match. But the function-level docstring above still describes the old inline mechanism — it says the callback "rebuilds skim's pool itself ([resync_pool]) on the same event-loop tick". After this change the callback no longer calls resync_pool itself; it queues resync_pool_action. Worth realigning that sentence (and its resync_pool link) so the two descriptions of the same mechanism don't diverge — the PR body's "rebuilds skim's pool from the mutated row list (resync_pool) on the same event-loop tick" has the same drift.

Removing a row with alt-x flashed the `>` pointer to the top of the list for a
frame before settling on the right row. The cause was structural to skim's
`reload`: `handle_reload` clears the item pool and restarts the matcher *before*
the new rows stream in, so the matcher runs once against the empty pool,
`Replace`s `item_list` with nothing, and skim's render clamp
(`items.is_empty() -> current = 0`) resets the cursor to the top. A reposition
action then snapped it back, but the reset frame was already painted.
(`no_clear_if_empty` doesn't help — its protective branch is gated on skim's
interactive mode, which the picker doesn't use.)

Replace the `reload`-based removal with a synchronous in-place pool resync. alt-x
is now a single Custom keybinding callback that runs the removal dispatch
(`AltXRemover::apply`) and rebuilds skim's pool from the mutated row list
(`resync_pool` / `resync_pool_action`) on the same event-loop tick. The pool is
filled before the matcher runs, so it only ever sees the post-removal list — never
empty — and `current` is preserved; the row that slides into the removed slot
lands under the cursor for free, with no flash, under a fuzzy filter too. This
deletes the whole reposition apparatus (net deletion in `picker/mod.rs`); the
dispatch moved into a `Send` `AltXRemover` since skim requires the callback to be
`Send`.

Two follow-on fixes surfaced while validating:

- Last-row preview: skim auto-repaints the preview across the matcher's `Replace`
  only on a selected-text change, which a last-row drop doesn't produce, so the
  pane kept showing the removed row. A settled-gated `run_preview_when_settled`
  restores the repaint.

- `--prs` streaming order: `on_skeleton` woke the `--prs` thread (`grid_slot.set`)
  before sending the skeleton batch, so with a fast forge call a PR row could win
  the race and take the reserved header slot, displacing the header — a
  microsecond race the alt-x rework tipped to fail, and the root of the flaky
  `test_switch_picker_preview_auto_refreshes_when_compute_lands`. The `--prs`
  thread is now woken only after the skeleton is sent.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@max-sixty
max-sixty force-pushed the fix-picker-altx-cursor-flash branch from a8a93c0 to d66bc6a Compare June 27, 2026 09:55
@max-sixty
max-sixty merged commit 57d0458 into main Jun 27, 2026
34 checks passed
@max-sixty
max-sixty deleted the fix-picker-altx-cursor-flash branch June 27, 2026 21:30
social4hyq pushed a commit to social4hyq/homebrew-core that referenced this pull request Sep 20, 2026
worktrunk 0.63.0

Created-by: HarmonybrewBot
Commit-by: HarmonybrewBot
Merged-by: HarmonybrewBot
Description: Created by `brew bump`

---

Created with `brew bump-formula-pr`.<details>
  <summary>release notes</summary>
  <pre>## Release Notes

### Improved

- **`[list] columns` can force a column on past `--full`**: Listing a column now overrides the `--full` / `[list] summary` presets — `columns = ["branch", "ci"]` shows the CI column without `--full`. Hard data-source prerequisites still apply: a listed `summary` with no `[commit.generation]` command, or `url` with no template, stays hidden, since listing can't conjure data that isn't configured. ([#3295](max-sixty/worktrunk#3295))

- **`Alt-r` in the picker refreshes the preview panes, not just the rows**: `Alt-r` re-collected the rows but kept serving cached preview content, so editing a tracked file and refreshing still showed the pre-edit diff. It now clears the preview cache too, recomputing the working-tree / log / branch-diff / upstream / summary tabs and re-fetching `pr` / `comments`. Unchanged branches re-read from the content-keyed on-disk cache, so only genuinely changed content pays a recompute. ([#3293](max-sixty/worktrunk#3293))

- **A narrowed `wt list` is now actually faster**: A narrowed `[list] columns` selection (e.g. `["branch", "path"]`) now runs only the git work its columns need. It previously ran every per-worktree `git status`, diff, and ahead/behind walk regardless, then discarded the unselected results — so a trimmed view was no faster than the full table, and on a repo with many dirty worktrees that discarded work was the bulk of the wall-clock cost. ([#3274](max-sixty/worktrunk#3274), thanks @jtaby for reporting)

- **Fewer duplicate git calls in `wt list --full`**: The two integration probes per row (the conflict bit for `main-state` and the clean-merge tree for the integration column) issued a byte-identical `git merge-tree`, and the shared default-branch tip was peeled to its tree once per row. Both are now deduplicated through the in-memory cache, so each resolves once per run instead of once per worktree. ([#3288](max-sixty/worktrunk#3288), [#3289](max-sixty/worktrunk#3289))

- **Picker `comments` tab avoids redundant forge fetches**: The picker's `comments` preview tab gained an on-disk cache keyed by the PR's `updatedAt` (which rides for free on the CI fetch the picker already makes), so a repeat `wt switch` skips the per-row `gh pr view --json comments` fetch when the thread is unchanged and paints the tab instantly instead of showing "Loading comments…". The cache is also primed from the `gh pr list` call the picker already makes, so the tab skips its own fetch even on a session's first open (including PRs with no comments). GitHub only. ([#3294](max-sixty/worktrunk#3294), [#3299](max-sixty/worktrunk#3299))

- **Statusline width comes from `COLUMNS`, not a parent-process walk**: `wt list statusline` used to spawn up to 10 `ps` calls plus `stty` per render to recover a terminal width, because Claude Code piped the subprocess with no inherited TTY. Claude Code now sets `COLUMNS`/`LINES` to the terminal dimensions before running the script (since v2.1.153), so the width comes straight from there — less a fixed 5-column margin for Claude Code's own UI — and the `ps`/`stty` walk is gone. On an older Claude Code that doesn't set `COLUMNS`, the line renders untruncated rather than walking the process tree. ([#3286](max-sixty/worktrunk#3286), closes [#2950](max-sixty/worktrunk#2950))

### Fixed

- **`wt list` diff and ahead/behind columns use the upstream default tip**: The `main↕` (ahead/behind) and `main…±` (diff) columns measured every branch against the *local* default-branch tip, so in a fork whose local `main` lagged its upstream they reported inflated counts — one fork branch showed `↑44` and `+∞ / -5K` when it was ~2 commits past the real upstream tip. They now diff against the same upstream-aware base the integration column already uses. ([#3280](max-sixty/worktrunk#3280))

- **Integrated branches no longer flash `✗` in `wt list`**: A squash-merged branch whose default branch later re-edited the same lines showed `✗` (would-conflict), even though `wt step prune` classified it as `⊂` (fully integrated) and removed it. The list now ranks the integration verdict above the downstream conflict, matching prune; a genuinely un-integrated conflict still shows `✗`. ([#3278](max-sixty/worktrunk#3278))

- **`wt list` divergence-overflow marker uses one emphasis level**: When an ahead/behind count overflows its digit budget, the `main↕` column's compact `C`/`K`/`∞` marker rendered the "behind" subcolumn as dim + bold (reading as bold red) instead of a clean one-level step. It now steps exactly one level — dim red → normal red — matching the "ahead" subcolumn, across `wt list` and the picker. ([#3303](max-sixty/worktrunk#3303))

- **Branch deletion on removal is atomic**: `wt remove` and prune now delete a branch with a compare-and-swap (`git update-ref -d <ref> <expected-sha>`) against the SHA the integration check already read, closing the window where a branch whose tip moved in between (e.g. a hook landing a commit) could be deleted. Such a branch is now retained with a clear message and a `wt remove -D <branch>` recovery hint. This also unifies the previously divergent safe-delete paths; explicit force-delete still uses `git branch -D`. ([#2903](max-sixty/worktrunk#2903))

- **`wt list` and picker Age/Message columns paint as soon as the commit batch lands**: These columns carry no async task — their data arrives with the initial `git log` batch — but stayed on the `·` placeholder until some slower task happened to redraw the row, so the commit message lagged behind a cache-warm Summary preview. They now paint the moment the batch lands. ([#3287](max-sixty/worktrunk#3287))

- **Picker `Alt-x` removal: no cursor flash, `--prs` rows preserved**: Removing a row with `Alt-x` flashed the `>` pointer to the top of the list for a frame, and in `--prs` mode made the streamed PR/MR rows vanish until the next `Alt-r`. Removal is now a synchronous in-place pool resync: the cursor lands on the row that slid up with no flash, and the PR/MR rows survive. ([#3268](max-sixty/worktrunk#3268), [#3275](max-sixty/worktrunk#3275))

- **Removable rows stay gray when selected in the picker**: A safe-to-delete worktree (integrated, or clean and even with the default branch) renders its row gray, but the gray vanished under the selection highlight — exactly when you're about to act on it. The gray now survives selection (selected row only; `wt list` and unselected rows are unchanged). ([#3267](max-sixty/worktrunk#3267))

- **Picker preview keeps its scroll when CI status arrives**: Scrolling down a diff and waiting a couple of seconds snapped it back to the top when the live CI fetch landed and re-rendered the pane. The re-render is now precise — a tab re-runs only when its own content would actually change — so a CI update no longer throws away the scroll position of an unrelated tab. ([#3292](max-sixty/worktrunk#3292))

- **Picker summary tab dims when there's nothing to summarize**: The summary preview tab (`5`) stayed lit on a clean branch with no commits ahead, unlike the diff tabs (1/3/4), which dim once their diff is known empty. It now dims in concert with them once both the branch diff and working tree are known empty. ([#3291](max-sixty/worktrunk#3291))

- **Picker default view keeps collect order**: With no query typed, the `wt switch` picker reordered rows by where each name's last `/` falls, so slash-bearing branches (`feature/…`, `perf/…`) sank toward the bottom and intermixed with other row kinds. The default view now preserves collect order. ([#3301](max-sixty/worktrunk#3301))

- **Picker branch-diff preview and summary use the upstream-aware base**: Like the `wt list` columns above, the picker's branch-diff preview pane and the LLM branch summary diffed against the raw local default branch, so a fork whose local default lagged upstream made them describe dozens of already-merged commits. They now use the same upstream-aware comparison base. ([#3305](max-sixty/worktrunk#3305))

- **Picker comment previews render fenced code blocks cleanly**: A fenced code block inside a PR/MR comment rendered as a garbled double gutter in the `wt switch` comments preview — alternating bar/no-bar lines with broken alignment. The code block now renders without the nested gutter. ([#3306](max-sixty/worktrunk#3306))

- **First-run hints show the config path wt actually loads from**: The picker's disabled-summary tab and the commit-generation setup prompt hardcoded `~/.config/worktrunk/config.toml`, so a user with `--config`, `WORKTRUNK_CONFIG_PATH`, or a non-default `$XDG_CONFIG_HOME` was told to edit a file wt never reads. Both now show the resolved path. ([#3290](max-sixty/worktrunk#3290), [#3298](max-sixty/worktrunk#3298))

### Internal

- **`-vv` trace and profiler accuracy**: `trace.log` is now purely human-readable, with the machine-parseable `[wt-trace]` fields living only in `trace.jsonl`; and the performance profile's cache analysis no longer reports stdin-driven commands (LLM `claude -p` calls, `git patch-id`) as duplicate re-runs, since their real input isn't captured in the command string. ([#3296](max-sixty/worktrunk#3296), [#3297](max-sixty/worktrunk#3297))

## Install worktrunk 0.63.0

### Install prebuilt binaries via shell script

`

See merge request: Harmonybrew/homebrew-core!13092
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