Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

feat(switch): show a scrollbar on the interactive picker list (#3198)

Maximilian Roos321494be75ec
diff --git a/src/commands/picker/mod.rs b/src/commands/picker/mod.rs
index 29d99037a..4d9385e06 100644
--- a/src/commands/picker/mod.rs
+++ b/src/commands/picker/mod.rs
@@ -819,6 +819,14 @@ pub fn handle_picker(
// shows just the `>` pointer (the row's own `display()` ANSI spans carry
// no background). skim 0.20's tuikit backend highlighted the row for free.
.highlight_line(true)
+ // Draw a scrollbar thumb on the item list when it overflows the view.
+ // skim's `▐` default is the clap `default_value`, gated on skim's `cli`
+ // feature; with `default-features = false` the library `Default` for
+ // this `String` field is empty, which skim reads as "no scrollbar".
+ // Setting it explicitly restores the thumb — without it a long worktree
+ // (or `--prs`) list scrolls with no position cue, made worse by
+ // `no_info(true)` below hiding the matched/total counter.
+ .scrollbar("▐".to_string())
// First line (header) non-selectable. `PICKER_HEADER_ROWS` mirrors this
// count so the alt-r cursor-reposition math stays in sync — keep them one.
.header_lines(PICKER_HEADER_ROWS)
diff --git a/tests/integration_tests/switch_picker.rs b/tests/integration_tests/switch_picker.rs
index 3c4450ebb..918bfc78a 100644
--- a/tests/integration_tests/switch_picker.rs
+++ b/tests/integration_tests/switch_picker.rs
@@ -609,6 +609,48 @@ fn test_switch_picker_with_branches(mut repo: TestRepo) {
});
}
+/// A list taller than the viewport renders skim's scrollbar thumb (`▐`) down
+/// the right edge of the item pane. The thumb only appears because the picker
+/// sets `.scrollbar("▐")` explicitly: skim's `▐` default lives in its clap
+/// `default_value`, gated on the `cli` feature we disable, so the library
+/// `Default` for the field is the empty string ("no scrollbar"). Without the
+/// explicit setting a long worktree/`--prs` list scrolls with no position cue.
+/// `--branches` overflows the 30-row test terminal cheaply (one `git branch`
+/// per row, no `git worktree add`).
+#[rstest]
+fn test_switch_picker_scrollbar_on_overflow(mut repo: TestRepo) {
+ repo.remove_fixture_worktrees();
+ repo.run_git(&["remote", "remove", "origin"]);
+
+ // Far more branches than the ~24 item rows the 30-row terminal can show, so
+ // the list is guaranteed to overflow and skim paints the scrollbar.
+ for i in 0..50 {
+ let name = format!("scroll-{i:02}");
+ repo.run_git(&["branch", name.as_str()]);
+ }
+
+ let env_vars = repo.test_env_vars();
+ let result = exec_in_pty_capture_before_abort(
+ wt_bin().to_str().unwrap(),
+ &["switch", "--branches"],
+ repo.root_path(),
+ &env_vars,
+ // `@ main` is the current worktree, always the top row of the list:
+ // gating on it confirms the item rows rendered before capture, and a
+ // regression fails fast with the list shown rather than via a 30s
+ // stabilize timeout (the role `orphan-branch` plays above).
+ &[("", Some("@ main"))],
+ );
+
+ assert_valid_abort_exit_code(result.exit_code);
+
+ let (list, _preview) = result.panels();
+ assert!(
+ list.contains('▐'),
+ "scrollbar thumb (▐) should render when the list overflows the viewport:\n{list}"
+ );
+}
+
/// Typing a gutter glyph filters the picker by row kind. `+` is the linked-
/// worktree glyph, so it narrows to linked worktrees — excluding the current
/// worktree (`@`) and branch rows (`/`). This is the end-to-end answer to "why