diff options
| author | Adam Lau <319494+we11adam@users.noreply.github.com> | 2026-07-29 07:36:16 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-07-29 02:36:16 +0300 |
| commit | a4b18b6e2130629a03a03fc1534226299aa83214 (patch) | |
| tree | e02ce9d0c93b36f37a143c4ae6b9d7bae9b26346 /src/app | |
| parent | 807033b8fc40bbf413332b2cae9de8fecf592c1b (diff) | |
fix: preserve navigate mode after pane focus (#1993)
refs #1850
Co-authored-by: Can Celik <ogulcancelik@gmail.com>
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/input/navigate.rs | 43 |
1 files changed, 39 insertions, 4 deletions
diff --git a/src/app/input/navigate.rs b/src/app/input/navigate.rs index 4cb2a4e1..93dfe77d 100644 --- a/src/app/input/navigate.rs +++ b/src/app/input/navigate.rs @@ -335,11 +335,17 @@ impl App { super::modal::open_rename_pane(&mut self.state, pane_id); } } - NavigateAction::FocusPaneLeft => self.focus_pane_direction_via_api(NavDirection::Left), - NavigateAction::FocusPaneDown => self.focus_pane_direction_via_api(NavDirection::Down), - NavigateAction::FocusPaneUp => self.focus_pane_direction_via_api(NavDirection::Up), + NavigateAction::FocusPaneLeft => { + self.focus_pane_direction_in_context(NavDirection::Left, context) + } + NavigateAction::FocusPaneDown => { + self.focus_pane_direction_in_context(NavDirection::Down, context) + } + NavigateAction::FocusPaneUp => { + self.focus_pane_direction_in_context(NavDirection::Up, context) + } NavigateAction::FocusPaneRight => { - self.focus_pane_direction_via_api(NavDirection::Right) + self.focus_pane_direction_in_context(NavDirection::Right, context) } NavigateAction::SwapPaneLeft => { self.swap_pane_direction_via_api(NavDirection::Left); @@ -522,6 +528,15 @@ impl App { ); } + fn focus_pane_direction_in_context(&mut self, direction: NavDirection, context: ActionContext) { + let preserve_navigate_mode = + context == ActionContext::Navigate && self.state.mode == Mode::Navigate; + self.focus_pane_direction_via_api(direction); + if preserve_navigate_mode { + self.state.mode = Mode::Navigate; + } + } + pub(crate) fn swap_pane_direction_via_api(&mut self, direction: NavDirection) { if let Some((ws_idx, source, target)) = self.directional_pane_swap_from_view(direction) { let source_pane_id = self.public_pane_id(ws_idx, source); @@ -2940,6 +2955,26 @@ navigate_pane_down = "ctrl+j" } #[tokio::test] + async fn navigate_focus_pane_keeps_navigate_mode_active() { + let mut app = app_with_test_workspaces(&["test"]); + let root = app.state.workspaces[0].tabs[0].root_pane; + let below = app.state.workspaces[0].test_split(Direction::Vertical); + app.state.workspaces[0].layout.focus_pane(below); + app.state.view.pane_infos = app.state.workspaces[0] + .active_tab() + .unwrap() + .layout + .panes(ratatui::layout::Rect::new(0, 0, 80, 24)); + app.state.mode = Mode::Navigate; + + app.handle_key(TerminalKey::new(KeyCode::Char('k'), KeyModifiers::empty())) + .await; + + assert_eq!(app.state.workspaces[0].focused_pane_id(), Some(root)); + assert_eq!(app.state.mode, Mode::Navigate); + } + + #[tokio::test] async fn no_op_prefix_action_exits_prefix_mode() { let (_api_tx, api_rx) = tokio::sync::mpsc::unbounded_channel(); let mut app = App::new( |
