aboutsummaryrefslogtreecommitdiff
path: root/src/app/input
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-29 18:57:13 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-29 18:57:13 +0300
commit97f78226bf1f34dcdef164291a9c50fddf448c6e (patch)
tree20f8793644f314521c6e064bef8ba4b25576524b /src/app/input
parent1a4e94e57e181379e2ed42d63a49fbc56ed1dba4 (diff)
fix: route tui modal mutations through api authority
Diffstat (limited to 'src/app/input')
-rw-r--r--src/app/input/mod.rs10
-rw-r--r--src/app/input/modal.rs73
-rw-r--r--src/app/input/mouse.rs98
3 files changed, 143 insertions, 38 deletions
diff --git a/src/app/input/mod.rs b/src/app/input/mod.rs
index 31a99c23..164c4dd4 100644
--- a/src/app/input/mod.rs
+++ b/src/app/input/mod.rs
@@ -45,8 +45,7 @@ mod terminal;
pub(crate) use self::{
modal::{
- handle_confirm_close_key, handle_context_menu_key, handle_global_menu_key,
- handle_keybind_help_key, handle_navigator_key, handle_rename_key, handle_resize_key,
+ handle_global_menu_key, handle_keybind_help_key, handle_navigator_key,
insert_navigator_search_text, insert_rename_input_text,
},
navigate::terminal_direct_navigation_action,
@@ -318,6 +317,13 @@ impl App {
MouseAction::SetSplitRatio { path, ratio } => {
self.set_split_ratio_via_api(path, ratio)
}
+ MouseAction::RenameModal(action) => {
+ self.apply_rename_mouse_action_via_api(action)
+ }
+ MouseAction::ConfirmCloseAccept => self.confirm_close_accept_via_api(),
+ MouseAction::ContextMenu { menu, idx } => {
+ self.apply_context_menu_action_via_api(menu, idx)
+ }
}
}
}
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),
_ => {}
diff --git a/src/app/input/mouse.rs b/src/app/input/mouse.rs
index 71c0cfbd..7f9f9cde 100644
--- a/src/app/input/mouse.rs
+++ b/src/app/input/mouse.rs
@@ -18,8 +18,7 @@ use crate::{
use super::WheelRouting;
use super::{
modal::{
- apply_context_menu_action, apply_global_menu_action, apply_rename_action,
- confirm_close_accept, confirm_close_cancel, global_menu_actions, leave_modal,
+ apply_global_menu_action, confirm_close_cancel, global_menu_actions, leave_modal,
modal_action_from_buttons, open_global_menu, open_new_tab_dialog, ModalAction,
},
settings::SettingsAction,
@@ -52,6 +51,12 @@ pub(super) enum MouseAction {
path: Vec<bool>,
ratio: f32,
},
+ RenameModal(ModalAction),
+ ConfirmCloseAccept,
+ ContextMenu {
+ menu: ContextMenuState,
+ idx: usize,
+ },
}
enum MobileMouseResult {
@@ -234,7 +239,9 @@ impl AppState {
(cancel, ModalAction::Cancel),
],
) {
- Some(ModalAction::Confirm) => confirm_close_accept(self),
+ Some(ModalAction::Confirm) => {
+ return Some(MouseAction::ConfirmCloseAccept);
+ }
Some(ModalAction::Cancel) | None => confirm_close_cancel(self),
_ => {}
}
@@ -396,15 +403,14 @@ impl AppState {
)
})
.unwrap_or(ModalAction::Cancel);
- apply_rename_action(self, action);
- return None;
+ return Some(MouseAction::RenameModal(action));
}
if self.mode == Mode::ContextMenu {
let item_idx = self.context_menu_item_at(mouse.column, mouse.row);
if let Some(menu) = self.context_menu.take() {
if let Some(idx) = item_idx {
- apply_context_menu_action(self, terminal_runtimes, menu, idx);
+ return Some(MouseAction::ContextMenu { menu, idx });
} else {
leave_modal(self);
}
@@ -900,8 +906,26 @@ impl AppState {
if self.on_tab_bar(mouse.column, mouse.row) =>
{
match mouse.kind {
- MouseEventKind::ScrollUp => self.previous_tab(),
- MouseEventKind::ScrollDown => self.next_tab(),
+ MouseEventKind::ScrollUp => {
+ if let Some(ws) = self.active.and_then(|i| self.workspaces.get(i)) {
+ if !ws.tabs.is_empty() {
+ let prev = if ws.active_tab == 0 {
+ ws.tabs.len() - 1
+ } else {
+ ws.active_tab - 1
+ };
+ return Some(MouseAction::FocusTab { tab_idx: prev });
+ }
+ }
+ }
+ MouseEventKind::ScrollDown => {
+ if let Some(ws) = self.active.and_then(|i| self.workspaces.get(i)) {
+ if !ws.tabs.is_empty() {
+ let next = (ws.active_tab + 1) % ws.tabs.len();
+ return Some(MouseAction::FocusTab { tab_idx: next });
+ }
+ }
+ }
_ => {}
}
}
@@ -1814,10 +1838,10 @@ mod tests {
use ratatui::layout::{Direction, Rect};
use super::super::{
- app_for_mouse_test, capture_snapshot, handle_context_menu_key, mouse, numbered_lines_bytes,
- root_layout_ratio,
+ app_for_mouse_test, capture_snapshot, mouse, numbered_lines_bytes, root_layout_ratio,
};
use super::*;
+ use crate::app::input::modal::handle_context_menu_key;
use crate::{
app::state::{ContextMenuKind, ContextMenuState, MenuListState, Mode, ViewLayout},
detect::{Agent, AgentState},
@@ -2450,6 +2474,31 @@ mod tests {
}
#[test]
+ fn clicking_rename_save_submits_workspace_rename_through_api_path() {
+ let mut app = app_for_mouse_test();
+ app.state.workspaces = vec![Workspace::test_new("old")];
+ app.state.active = Some(0);
+ app.state.selected = 0;
+ app.state.mode = Mode::RenameWorkspace;
+ app.state.name_input = "new".into();
+
+ crate::ui::compute_view(&mut app.state, Rect::new(0, 0, 106, 24));
+ let inner = app.state.rename_modal_inner().unwrap();
+ let (save, _, _) = crate::ui::rename_button_rects(inner);
+
+ app.handle_mouse(mouse(
+ MouseEventKind::Down(MouseButton::Left),
+ save.x,
+ save.y,
+ ));
+
+ assert_eq!(app.state.workspaces[0].custom_name.as_deref(), Some("new"));
+ assert!(app.event_hub.events_after(0).iter().any(|(_, event)| {
+ matches!(event.event, crate::api::schema::EventKind::WorkspaceRenamed)
+ }));
+ }
+
+ #[test]
fn clicking_open_worktree_row_selects_and_requests_open() {
let mut app = app_for_mouse_test();
app.state.mode = Mode::OpenExistingWorktree;
@@ -2615,6 +2664,35 @@ mod tests {
assert_eq!(app.state.workspaces[0].display_name(), "a");
}
+ #[test]
+ fn clicking_context_menu_close_routes_through_api_path() {
+ let mut app = app_for_mouse_test();
+ app.state.workspaces = vec![Workspace::test_new("a"), Workspace::test_new("b")];
+ app.state.active = Some(0);
+ app.state.selected = 0;
+ app.state.confirm_close = false;
+ app.state.context_menu = Some(ContextMenuState {
+ kind: ContextMenuKind::Workspace { ws_idx: 1 },
+ x: 2,
+ y: 2,
+ list: MenuListState::new(1),
+ });
+ app.state.mode = Mode::ContextMenu;
+
+ let menu = app.state.context_menu_rect().unwrap();
+ app.handle_mouse(mouse(
+ MouseEventKind::Down(MouseButton::Left),
+ menu.x + 2,
+ menu.y + 2,
+ ));
+
+ assert_eq!(app.state.workspaces.len(), 1);
+ assert_eq!(app.state.workspaces[0].display_name(), "a");
+ assert!(app.event_hub.events_after(0).iter().any(|(_, event)| {
+ matches!(event.event, crate::api::schema::EventKind::WorkspaceClosed)
+ }));
+ }
+
#[cfg(unix)]
#[tokio::test]
async fn keyboard_context_menu_split_keeps_new_runtime() {