Skip to content

fix: preserve sort order across tab events, add manual reorder - #5

Merged
rhuss merged 8 commits into
mainfrom
fix/sort-persistence-and-reorder
Jun 28, 2026
Merged

rhuss merged 8 commits into
mainfrom
fix/sort-persistence-and-reorder

Conversation

@rhuss

@rhuss rhuss commented Jun 28, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Sort order (S key) now survives tab creation and closure — dead pane_ids are pruned, new sessions appended at the end
  • Fix highlight flicker when using Alt-I/O (MoveTab) while sorted by anchoring the viewport scroll to focused_pane_id instead of active_tab_index
  • Add Shift+J/K in navigate mode to manually move sessions up/down in the sort order (initializes from tab order if no sort is active)

Test plan

  • cargo test — 353 tests pass (4 new)
  • cargo clippy — no warnings
  • Manual: press S to sort, create a new tab — sort persists with new session at bottom
  • Manual: press S to sort, close a tab — sort persists without the removed session
  • Manual: press S to sort, Alt-I/O — no highlight flicker
  • Manual: enter navigate, Shift+J/K — sessions swap positions (works with or without prior S sort)

Assisted-By: 🤖 Claude Code


Open in Devin Review

Summary by CodeRabbit

  • New Features
    • Added navigation-mode shortcuts J / K to move the selected session up or down in the current virtual sort order.
    • Added S to quickly sort sessions by activity tier (snapshot).
    • Improved sidebar viewport behavior to keep the selection anchored more consistently when sorting is active.
  • Bug Fixes
    • Preserves the virtual sort order when tabs are added or closed, removing only entries that no longer exist.
    • Moving sessions now safely handles boundaries and correctly initializes ordering when needed.

Sort order (S key) now survives tab creation and closure instead of
being cleared. Dead pane_ids are removed and new sessions are appended
at the end of the sorted list.

Fix highlight flicker when using Alt-I/O (MoveTab) while sorted by
using focused_pane_id instead of active_tab_index for the viewport
scroll anchor.

Add Shift+J/K keybindings in navigate mode to manually move sessions
up/down within the sort order. If no sort is active, initializes one
from the current tab order.

Assisted-By: 🤖 Claude Code
@coderabbitai

coderabbitai Bot commented Jun 28, 2026 •

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@rhuss, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 50 minutes and 43 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d868aea2-6ce3-4bbe-b5cc-bea4dff2016b

📥 Commits

Reviewing files that changed from the base of the PR and between 3e0363e and 2f074a7.

📒 Files selected for processing (4)
  • cc-zellij-plugin/src/controller/hooks.rs
  • cc-zellij-plugin/src/sidebar_plugin/input.rs
  • cc-zellij-plugin/src/sidebar_plugin/render.rs
  • specs/074-virtual-sort-fix/spec.md
📝 Walkthrough

Walkthrough

Adds MoveUp/MoveDown to the action protocol, wires J/K sidebar shortcuts to them, and reorders sort_order in the controller. Sort state is now preserved across tab/session changes, and sidebar viewport anchoring uses the focused pane when sorting is active.

Changes

Session Move Up/Down

Layer / File(s) Summary
Action protocol and sidebar bindings
cc-zellij-plugin/src/lib.rs, cc-zellij-plugin/src/sidebar_plugin/input.rs, README.md, docs/modules/using/pages/navigation.adoc
Adds MoveUp and MoveDown to ActionType, dispatches them from Navigate-mode J/K keys, and updates the shortcut documentation.
Move handling and delete cleanup
cc-zellij-plugin/src/controller/actions.rs
Routes move actions into handle_move, swaps adjacent sort_order entries, removes deleted pane ids from sort_order, and adds unit tests for move behavior.
Virtual sort lifecycle maintenance
cc-zellij-plugin/src/controller/events.rs, cc-zellij-plugin/src/controller/hooks.rs, cc-zellij-plugin/src/controller/state.rs
Preserves sort_order across tab changes, prunes stale pane ids during cleanup and session end, and updates tests for add/close persistence.
Viewport anchoring and help text
cc-zellij-plugin/src/sidebar_plugin/render.rs
Updates visible_range to anchor by pane id when sort is active, passes the new inputs from render_sidebar, and changes the help text to J/K.
Virtual sort spec updates
specs/074-virtual-sort-fix/spec.md
Rewrites the spec to match one-shot recomputation, persistent sort across tab changes, the four-tier model, and the updated viewport rule.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Poem

🐇 J hops down, K hops up in line,
The sidebar keeps its order fine.
Sort stays snug when tabs appear or close,
And pane-id scrolls where the rabbit goes.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main changes: preserving sort order across tab events and adding manual reordering.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/sort-persistence-and-reorder

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.

coderabbitai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

Applied fixes from bot review comments:
- Comment #3488162812: mark render dirty on sort_order initialization (CodeRabbit)
- Comment #3488162818: append new sessions in tab_index order (CodeRabbit)
- Comment #3488162823: use correct pane_id source for scroll anchor in navigate mode (CodeRabbit)
- Comment #3488164757: clean sort_order in all session removal paths (Devin)

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

rhuss added 2 commits June 28, 2026 18:34
Reconciled spec with code after sort persistence and manual reorder
features. Key changes:

- FR-002: 3 tiers -> 4 tiers (Done separated from Idle)
- FR-006: Toggle behavior -> one-shot re-sort snapshot
- FR-008: Auto-deactivate on tab change -> preserve and update
- FR-011-013: New requirements for manual reorder (Shift+J/K),
  sort_order cleanup on session removal, and scroll anchor fix
- User stories updated to match current behavior

Assisted-By: 🤖 Claude Code
Applied fixes from bot review comments:
- Comment #3488186164: add J/K shortcuts to README and Antora navigation docs

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

Applied fixes from bot review comments:
- Comment #3488210895: clean sort_order in SessionEnd hook removal path (Devin)
- Comment #3488210927: use immediate broadcast_render for Move operations (Devin)

Assisted-By: 🤖 Claude Code
devin-ai-integration[bot]

This comment was marked as resolved.

Applied fix from bot review comment:
- Comment #3488247598: clear render_dirty after broadcast_render to prevent redundant double-broadcast on next timer tick (Devin)

Assisted-By: 🤖 Claude Code

This comment was marked as resolved.

coderabbitai[bot]

This comment was marked as resolved.

rhuss added 2 commits June 28, 2026 19:18
Applied fixes from bot review comments:
- Comment #3488251617: fall back to active_tab_index when pane_id anchor missing in sorted mode (Copilot)
- Comment #3488251624: add tests for sorted scroll anchoring and fallback (Copilot)
- Comment #3488251630: add tests for J/K move keybindings in navigate mode (Copilot)

Assisted-By: 🤖 Claude Code
Applied fixes from bot review comments:
- Comment #3488254556: add pending_git_branch cleanup in SessionEnd hook (CodeRabbit)
- Comment #3488254564: align spec acceptance scenario and SC-001 with 4-tier sort (CodeRabbit)

Assisted-By: 🤖 Claude Code
@rhuss
rhuss merged commit 4d44477 into main Jun 28, 2026
6 of 7 checks passed
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fixes from bot review comments:
- Comment #3488162812: mark render dirty on sort_order initialization (CodeRabbit)
- Comment #3488162818: append new sessions in tab_index order (CodeRabbit)
- Comment #3488162823: use correct pane_id source for scroll anchor in navigate mode (CodeRabbit)
- Comment #3488164757: clean sort_order in all session removal paths (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fixes from bot review comments:
- Comment #3488186164: add J/K shortcuts to README and Antora navigation docs

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fixes from bot review comments:
- Comment #3488210895: clean sort_order in SessionEnd hook removal path (Devin)
- Comment #3488210927: use immediate broadcast_render for Move operations (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fix from bot review comment:
- Comment #3488247598: clear render_dirty after broadcast_render to prevent redundant double-broadcast on next timer tick (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fixes from bot review comments:
- Comment #3488251617: fall back to active_tab_index when pane_id anchor missing in sorted mode (Copilot)
- Comment #3488251624: add tests for sorted scroll anchoring and fallback (Copilot)
- Comment #3488251630: add tests for J/K move keybindings in navigate mode (Copilot)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 18, 2026
Applied fixes from bot review comments:
- Comment #3488254556: add pending_git_branch cleanup in SessionEnd hook (CodeRabbit)
- Comment #3488254564: align spec acceptance scenario and SC-001 with 4-tier sort (CodeRabbit)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fixes from bot review comments:
- Comment #3488162812: mark render dirty on sort_order initialization (CodeRabbit)
- Comment #3488162818: append new sessions in tab_index order (CodeRabbit)
- Comment #3488162823: use correct pane_id source for scroll anchor in navigate mode (CodeRabbit)
- Comment #3488164757: clean sort_order in all session removal paths (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fixes from bot review comments:
- Comment #3488186164: add J/K shortcuts to README and Antora navigation docs

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fixes from bot review comments:
- Comment #3488210895: clean sort_order in SessionEnd hook removal path (Devin)
- Comment #3488210927: use immediate broadcast_render for Move operations (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fix from bot review comment:
- Comment #3488247598: clear render_dirty after broadcast_render to prevent redundant double-broadcast on next timer tick (Devin)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fixes from bot review comments:
- Comment #3488251617: fall back to active_tab_index when pane_id anchor missing in sorted mode (Copilot)
- Comment #3488251624: add tests for sorted scroll anchoring and fallback (Copilot)
- Comment #3488251630: add tests for J/K move keybindings in navigate mode (Copilot)

Assisted-By: 🤖 Claude Code
rhuss added a commit that referenced this pull request Aug 19, 2026
Applied fixes from bot review comments:
- Comment #3488254556: add pending_git_branch cleanup in SessionEnd hook (CodeRabbit)
- Comment #3488254564: align spec acceptance scenario and SC-001 with 4-tier sort (CodeRabbit)

Assisted-By: 🤖 Claude Code
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