Skip to main content

codetether_agent/tui/app/state/
session_nav.rs

1//! Session list navigation and filtering methods.
2
3use crate::session::SessionSummary;
4
5impl super::AppState {
6    pub fn sessions_select_prev(&mut self) {
7        if self.selected_session > 0 {
8            self.selected_session -= 1;
9        }
10    }
11
12    pub fn sessions_select_next(&mut self) {
13        if self.selected_session + 1 < self.filtered_sessions().len() {
14            self.selected_session += 1;
15        }
16    }
17
18    pub fn filtered_sessions(&self) -> Vec<(usize, &SessionSummary)> {
19        if self.session_filter.is_empty() {
20            self.sessions.iter().enumerate().collect()
21        } else {
22            let filter = self.session_filter.to_lowercase();
23            self.sessions
24                .iter()
25                .enumerate()
26                .filter(|(_, s)| {
27                    s.title
28                        .as_deref()
29                        .unwrap_or("")
30                        .to_lowercase()
31                        .contains(&filter)
32                        || s.id.to_lowercase().contains(&filter)
33                })
34                .collect()
35        }
36    }
37
38    pub fn clear_session_filter(&mut self) {
39        self.session_filter.clear();
40        self.selected_session = 0;
41    }
42
43    pub fn session_filter_backspace(&mut self) {
44        self.session_filter.pop();
45        self.selected_session = 0;
46    }
47
48    pub fn session_filter_push(&mut self, c: char) {
49        self.session_filter.push(c);
50        self.selected_session = 0;
51    }
52}