steer_tui/tui/handlers/
edit_selection.rs

1use crate::error::Result;
2use crate::tui::Tui;
3use ratatui::crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
4
5impl Tui {
6    pub async fn handle_edit_selection_mode(&mut self, key: KeyEvent) -> Result<bool> {
7        match (key.code, key.modifiers) {
8            (KeyCode::Esc, _) | (KeyCode::Char('c'), KeyModifiers::CONTROL) => {
9                // Exit edit selection mode
10                self.input_mode = self.default_input_mode();
11                self.input_panel_state.clear_edit_selection();
12            }
13            (KeyCode::Enter, _) => {
14                // Select the currently highlighted message
15                if let Some((message_id, _)) = self.input_panel_state.get_selected_message() {
16                    let message_id = message_id.clone();
17                    self.enter_edit_mode(&message_id);
18                    self.input_panel_state.clear_edit_selection();
19                }
20            }
21            (KeyCode::Up, _) | (KeyCode::Char('k'), _) => {
22                // Move selection up
23                self.input_panel_state.edit_selection_prev();
24                if let Some(id) = self.input_panel_state.get_hovered_id() {
25                    let id = id.to_string();
26                    self.scroll_to_message_id(&id);
27                }
28            }
29            (KeyCode::Down, _) | (KeyCode::Char('j'), _) => {
30                // Move selection down
31                self.input_panel_state.edit_selection_next();
32                if let Some(id) = self.input_panel_state.get_hovered_id() {
33                    let id = id.to_string();
34                    self.scroll_to_message_id(&id);
35                }
36            }
37            _ => {}
38        }
39        Ok(false)
40    }
41}