Skip to content

Commit 16a41d3

Browse files
committed
add interactive mode nav changes
1 parent 1807994 commit 16a41d3

File tree

2 files changed

+28
-10
lines changed

2 files changed

+28
-10
lines changed

src/commands/interactive/command.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@ where
520520
}
521521
if matches!(self.selected, Some(0)) && !super::GLOBAL_ACTIONS.is_empty() {
522522
self.focus = Focus::GlobalActions;
523+
self.global_action_selected = super::GLOBAL_ACTIONS.len().saturating_sub(1);
523524
return;
524525
}
525526
let next = match self.selected {
@@ -531,15 +532,7 @@ where
531532
}
532533
Focus::Actions => self.move_action(-1),
533534
Focus::GlobalActions => {
534-
if self.global_action_selected == 0 {
535-
if !self.worktrees.is_empty() {
536-
self.focus = Focus::Worktrees;
537-
if self.selected.is_none() {
538-
self.selected = Some(0);
539-
}
540-
self.sync_selection(state);
541-
}
542-
} else {
535+
if self.global_action_selected > 0 {
543536
self.move_global_action(-1);
544537
}
545538
}

src/commands/interactive/tests.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,11 +302,36 @@ fn cd_to_root_global_action_exits() -> Result<()> {
302302

303303
#[test]
304304
fn up_from_top_moves_to_global_actions() -> Result<()> {
305+
let backend = TestBackend::new(40, 12);
306+
let terminal = Terminal::new(backend)?;
307+
let events = StubEvents::new(vec![key(KeyCode::Up), key(KeyCode::Enter)]);
308+
309+
let worktrees = entries(&["alpha"]);
310+
let command = InteractiveCommand::new(
311+
terminal,
312+
events,
313+
PathBuf::from("/tmp/worktrees"),
314+
worktrees,
315+
vec![String::from("main")],
316+
Some(String::from("main")),
317+
);
318+
319+
let result = command.run(|_| Ok(()), |_, _| Ok(()))?;
320+
321+
assert_eq!(result, Some(String::from(super::REPO_ROOT_SELECTION)));
322+
323+
Ok(())
324+
}
325+
326+
#[test]
327+
fn up_from_top_after_tabbing_picks_last_global_action() -> Result<()> {
305328
let backend = TestBackend::new(40, 12);
306329
let terminal = Terminal::new(backend)?;
307330
let events = StubEvents::new(vec![
331+
key(KeyCode::Tab),
332+
key(KeyCode::Tab),
333+
key(KeyCode::Tab),
308334
key(KeyCode::Up),
309-
key(KeyCode::Right),
310335
key(KeyCode::Enter),
311336
]);
312337

0 commit comments

Comments
 (0)