Skip to content

Commit bfccb6d

Browse files
committed
improve interactive ux
1 parent 9289def commit bfccb6d

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/commands/interactive/command.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,10 @@ where
788788
match self.focus {
789789
Focus::Worktrees => {
790790
if self.worktrees.is_empty() {
791+
if !super::GLOBAL_ACTIONS.is_empty() {
792+
self.focus = Focus::GlobalActions;
793+
self.global_action_selected = 0;
794+
}
791795
return;
792796
}
793797
let next = match self.selected {

src/commands/interactive/tests.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,3 +628,47 @@ fn up_with_no_worktrees_moves_to_global_actions() -> Result<()> {
628628

629629
Ok(())
630630
}
631+
632+
#[test]
633+
fn down_with_no_worktrees_opens_create_dialog() -> Result<()> {
634+
let backend = TestBackend::new(60, 18);
635+
let terminal = Terminal::new(backend)?;
636+
let events = StubEvents::new(vec![
637+
key(KeyCode::Down),
638+
key(KeyCode::Enter),
639+
char_key('n'),
640+
char_key('e'),
641+
char_key('w'),
642+
key(KeyCode::Tab),
643+
key(KeyCode::Tab),
644+
key(KeyCode::Enter),
645+
key(KeyCode::Enter),
646+
]);
647+
648+
let worktrees = Vec::new();
649+
let command = InteractiveCommand::new(
650+
terminal,
651+
events,
652+
PathBuf::from("/tmp/worktrees"),
653+
worktrees,
654+
vec![String::from("main")],
655+
Some(String::from("main")),
656+
);
657+
658+
let mut created = Vec::new();
659+
let result = command.run(
660+
|_, _| panic!("remove should not be called"),
661+
|name, base| {
662+
created.push((name.to_string(), base.map(|b| b.to_string())));
663+
Ok(())
664+
},
665+
)?;
666+
667+
assert_eq!(result, Some(Selection::Worktree(String::from("new"))));
668+
assert_eq!(
669+
created,
670+
vec![(String::from("new"), Some(String::from("main")))]
671+
);
672+
673+
Ok(())
674+
}

0 commit comments

Comments
 (0)