fix: derive active worktree from sidebar cursor - #46
Merged
Conversation
Adding or removing a worktree updated the sidebar selection but left the main pane showing the previously-active worktree (or the placeholder even when the cursor had moved to a survivor). The two were tracked independently — `ui.cursor` for sidebar highlight, `ui.active_worktree` for the main pane — and every mutation site had to remember to sync them. Make the cursor the single source of truth: `active_worktree_id()` now derives from the cursor, so navigating in the sidebar always refreshes the main pane and there's no separate "commit" step. - `remap_worktree_state` also remaps the cursor by path now, with fallbacks for vanished paths and emptied lists, so reorders and FS events keep the main pane in sync. - `try_create_worktree_modal` lands the cursor on the just-created worktree by path lookup — git lists alphabetically, so the previous "tail of the list" assumption picked the wrong row on macOS. - Persistence keeps using path identity for cross-session survival: `to_persisted` derives the path from the cursor, `apply_persisted` resolves it back to indices. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adding or removing a worktree updated the sidebar selection but left the main pane showing the previously-active worktree (or the placeholder even when the cursor had moved to a survivor). Sidebar selection (
ui.cursor, index-based) and main-pane driver (ui.active_worktree, path-based) were two independent fields that every mutation site had to remember to sync — and several didn't.This makes the cursor the single source of truth:
active_worktree_id()derives fromui.cursor, so navigating in the sidebar always refreshes the main pane. No separate "commit" step needed.remap_worktree_statealso remaps the cursor by path, with fallbacks for vanished paths and emptied lists, so reorders and FS events keep the main pane in sync.try_create_worktree_modallands the cursor on the just-created worktree by path lookup — git lists alphabetically, so the previous "tail of the list" assumption picked the wrong row on macOS.to_persistedderives the path from the cursor;apply_persistedresolves it back to indices.Test plan
cargo test— 142/142 pass, including new tests for cursor remap on reorder, on missing-path fallback, and on emptied-list fallbackcargo clippy --all-targets -- -D warningscleancargo fmt --checkclean🤖 Generated with Claude Code