diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-29 18:57:13 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-29 18:57:13 +0300 |
| commit | 97f78226bf1f34dcdef164291a9c50fddf448c6e (patch) | |
| tree | 20f8793644f314521c6e064bef8ba4b25576524b /src/app/input/modal.rs | |
| parent | 1a4e94e57e181379e2ed42d63a49fbc56ed1dba4 (diff) | |
fix: route tui modal mutations through api authority
Diffstat (limited to 'src/app/input/modal.rs')
| -rw-r--r-- | src/app/input/modal.rs | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/src/app/input/modal.rs b/src/app/input/modal.rs index 2c3f4e4a..e63cdb70 100644 --- a/src/app/input/modal.rs +++ b/src/app/input/modal.rs @@ -1,5 +1,7 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers}; -use ratatui::layout::{Direction, Rect}; +#[cfg(test)] +use ratatui::layout::Direction; +use ratatui::layout::Rect; use crate::{ app::{ @@ -426,6 +428,7 @@ pub(super) const SETTINGS_ACTIONS: &[ModalActionSpec<ModalAction>] = &[ }, ]; +#[cfg(test)] pub(super) fn apply_rename_action(state: &mut AppState, action: ModalAction) { match action { ModalAction::Save => { @@ -588,12 +591,7 @@ fn delete_rename_input_word(state: &mut AppState) { } } -pub(crate) fn handle_rename_key(state: &mut AppState, key: KeyEvent) { - if let Some(action) = modal_action_from_key(&key, RENAME_ACTIONS) { - apply_rename_action(state, action); - return; - } - +fn handle_rename_edit_key(state: &mut AppState, key: KeyEvent) { match key.code { KeyCode::Char('u') if key.modifiers.contains(KeyModifiers::CONTROL) => { clear_rename_input(state); @@ -618,6 +616,17 @@ pub(crate) fn handle_rename_key(state: &mut AppState, key: KeyEvent) { } } +#[cfg(test)] +pub(crate) fn handle_rename_key(state: &mut AppState, key: KeyEvent) { + if let Some(action) = modal_action_from_key(&key, RENAME_ACTIONS) { + apply_rename_action(state, action); + return; + } + + handle_rename_edit_key(state, key); +} + +#[cfg(test)] pub(crate) fn handle_resize_key(state: &mut AppState, raw_key: TerminalKey) { let key = raw_key.as_key_event(); if key.code == KeyCode::Esc @@ -646,6 +655,7 @@ pub(super) fn open_confirm_close(state: &mut AppState) { state.mode = Mode::ConfirmClose; } +#[cfg(test)] pub(super) fn confirm_close_accept(state: &mut AppState) { state.close_selected_workspace(); if state.workspaces.is_empty() { @@ -659,6 +669,7 @@ pub(super) fn confirm_close_cancel(state: &mut AppState) { state.mode = Mode::Navigate; } +#[cfg(test)] pub(crate) fn handle_confirm_close_key(state: &mut AppState, key: KeyEvent) { match modal_action_from_key(&key, CONFIRM_CLOSE_ACTIONS) { Some(ModalAction::Confirm) => confirm_close_accept(state), @@ -667,6 +678,7 @@ pub(crate) fn handle_confirm_close_key(state: &mut AppState, key: KeyEvent) { } } +#[cfg(test)] pub(super) fn apply_context_menu_action( state: &mut AppState, terminal_runtimes: &mut crate::terminal::TerminalRuntimeRegistry, @@ -870,6 +882,7 @@ pub(super) fn apply_context_menu_action( } } +#[cfg(test)] pub(crate) fn handle_context_menu_key( state: &mut AppState, terminal_runtimes: &mut crate::terminal::TerminalRuntimeRegistry, @@ -903,19 +916,11 @@ pub(crate) fn handle_context_menu_key( impl App { pub(crate) fn handle_rename_key_via_api(&mut self, key: KeyEvent) { if let Some(action) = modal_action_from_key(&key, RENAME_ACTIONS) { - match action { - ModalAction::Save => self.save_rename_modal_via_api(), - ModalAction::Clear => { - self.state.name_input.clear(); - self.state.name_input_replace_on_type = false; - } - ModalAction::Cancel => cancel_rename_modal(&mut self.state), - _ => {} - } + self.apply_rename_mouse_action_via_api(action); return; } - handle_rename_key(&mut self.state, key); + handle_rename_edit_key(&mut self.state, key); } fn save_rename_modal_via_api(&mut self) { @@ -1006,6 +1011,30 @@ impl App { cancel_rename_modal(&mut self.state); } + pub(super) fn apply_rename_mouse_action_via_api(&mut self, action: ModalAction) { + match action { + ModalAction::Save => self.save_rename_modal_via_api(), + ModalAction::Clear => { + self.state.name_input.clear(); + self.state.name_input_replace_on_type = false; + } + ModalAction::Cancel => cancel_rename_modal(&mut self.state), + _ => {} + } + } + + pub(super) fn confirm_close_accept_via_api(&mut self) { + let ws_idx = self.state.selected; + if ws_idx < self.state.workspaces.len() { + self.close_workspace_idx_via_api(ws_idx); + } + self.state.mode = if self.state.active.is_some() { + Mode::Terminal + } else { + Mode::Navigate + }; + } + pub(crate) fn handle_resize_key_via_api(&mut self, raw_key: TerminalKey) { let key = raw_key.as_key_event(); if key.code == KeyCode::Esc @@ -1043,15 +1072,7 @@ impl App { pub(crate) fn handle_confirm_close_key_via_api(&mut self, key: KeyEvent) { match modal_action_from_key(&key, CONFIRM_CLOSE_ACTIONS) { Some(ModalAction::Confirm) => { - let ws_idx = self.state.selected; - if ws_idx < self.state.workspaces.len() { - self.close_workspace_idx_via_api(ws_idx); - } - self.state.mode = if self.state.active.is_some() { - Mode::Terminal - } else { - Mode::Navigate - }; + self.confirm_close_accept_via_api(); } Some(ModalAction::Cancel) => confirm_close_cancel(&mut self.state), _ => {} |
