Skip to main content

codetether_agent/tui/app/input/
backspace.rs

1//! Backspace handling across TUI view modes.
2//!
3//! Deletes the character before the cursor in whichever
4//! input buffer is currently active — symbol search, bus
5//! filter, model filter, file picker, or chat.
6//!
7//! # Examples
8//!
9//! ```ignore
10//! handle_backspace(&mut app).await;
11//! ```
12
13use crate::tui::app::state::App;
14use crate::tui::app::symbols::{refresh_symbol_search, symbol_search_active};
15use crate::tui::models::{InputMode, ViewMode};
16
17/// Delete the character before the cursor.
18///
19/// Delegates to symbol search, bus filter, model filter,
20/// file picker, or chat input depending on the active view.
21/// Resets input mode to `Normal` when the chat input becomes
22/// empty.
23///
24/// # Examples
25///
26/// ```ignore
27/// handle_backspace(&mut app).await;
28/// ```
29pub async fn handle_backspace(app: &mut App) {
30    if symbol_search_active(app) {
31        app.state.symbol_search.handle_backspace();
32        refresh_symbol_search(app).await;
33    } else if app.state.view_mode == ViewMode::Bus && app.state.bus_log.filter_input_mode {
34        app.state.bus_log.pop_filter_char();
35        app.state.status = if app.state.bus_log.filter.is_empty() {
36            "Protocol filter cleared".to_string()
37        } else {
38            format!("Protocol filter: {}", app.state.bus_log.filter)
39        };
40    } else if app.state.view_mode == ViewMode::Model {
41        app.state.model_filter_backspace();
42    } else if app.state.view_mode == ViewMode::FilePicker {
43        crate::tui::app::file_picker::file_picker_filter_backspace(app);
44    } else if app.state.view_mode == ViewMode::Chat {
45        app.state.delete_backspace();
46        if app.state.input.is_empty() {
47            app.state.input_mode = InputMode::Normal;
48        } else if app.state.input.starts_with('/') {
49            app.state.input_mode = InputMode::Command;
50        }
51    }
52}