Skip to content

Commit ddb99a2

Browse files
committed
better interactive nav
1 parent 831e2b5 commit ddb99a2

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/commands/interactive/command.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,6 +516,11 @@ where
516516
match self.focus {
517517
Focus::Worktrees => {
518518
if self.worktrees.is_empty() {
519+
if !super::GLOBAL_ACTIONS.is_empty() {
520+
self.focus = Focus::GlobalActions;
521+
self.global_action_selected =
522+
super::GLOBAL_ACTIONS.len().saturating_sub(1);
523+
}
519524
return;
520525
}
521526
if matches!(self.selected, Some(0)) && !super::GLOBAL_ACTIONS.is_empty() {

src/commands/interactive/tests.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ fn up_from_top_moves_to_global_actions() -> Result<()> {
318318

319319
let result = command.run(|_| Ok(()), |_, _| Ok(()))?;
320320

321-
assert_eq!(result, Some(String::from(super::REPO_ROOT_SELECTION)));
321+
assert_eq!(result, Some(Selection::RepoRoot));
322322

323323
Ok(())
324324
}
@@ -351,3 +351,26 @@ fn up_from_top_after_tabbing_picks_last_global_action() -> Result<()> {
351351

352352
Ok(())
353353
}
354+
355+
#[test]
356+
fn up_with_no_worktrees_moves_to_global_actions() -> Result<()> {
357+
let backend = TestBackend::new(40, 12);
358+
let terminal = Terminal::new(backend)?;
359+
let events = StubEvents::new(vec![key(KeyCode::Up), key(KeyCode::Enter)]);
360+
361+
let worktrees = Vec::new();
362+
let command = InteractiveCommand::new(
363+
terminal,
364+
events,
365+
PathBuf::from("/tmp/worktrees"),
366+
worktrees,
367+
vec![String::from("main")],
368+
Some(String::from("main")),
369+
);
370+
371+
let result = command.run(|_| Ok(()), |_, _| Ok(()))?;
372+
373+
assert_eq!(result, Some(Selection::RepoRoot));
374+
375+
Ok(())
376+
}

0 commit comments

Comments
 (0)