Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.
fix(tui): correct slash command suggestions count, filtering, and navigation
Samir Hossainsb9955bd1944a
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rsindex d62006b..ca474a9 100644--- a/src/tui/app/keyboard.rs+++ b/src/tui/app/keyboard.rs@@ -143,23 +143,30 @@ impl App {self.state.set_status(String::new(), 150);}KeyCode::Enter => {- let query = self.state.search_query.trim().to_string();+ let selected_opt = self+ .state+ .suggest_index+ .and_then(|idx| self.state.search_suggestions.get(idx).cloned());++ let query = if let Some(sug) = selected_opt {+ sug+ } else {+ self.state.search_query.trim().to_string()+ };+if !query.is_empty() {- let selected_suggestion = self.state.suggest_index.is_some();+ self.state.search_query = query.clone();self.state.input_mode = InputMode::Normal;self.state.search_suggestions.clear();self.state.suggest_index = None;self.state.search_list_state.select(None);self.state.last_search_edit = std::time::Instant::now();- let action = if selected_suggestion {- Action::SelectSuggestion { query }- } else {- Action::Search {+ self.action_sender+ .send(Action::Search {query,force_refresh: false,- }- };- self.action_sender.send(action).ok();+ })+ .ok();}}KeyCode::Backspace => {@@ -179,10 +186,6 @@ impl App {Some(i) => i - 1,};self.state.suggest_index = Some(next_idx);- if let Some(sug) = self.state.search_suggestions.get(next_idx) {- self.state.search_query = sug.clone();- self.state.last_suggest_query = self.state.search_query.trim().to_string();- }}KeyCode::Down if !self.state.search_suggestions.is_empty() => {let max_idx = self.state.search_suggestions.len() - 1;@@ -192,10 +195,6 @@ impl App {Some(i) => i + 1,};self.state.suggest_index = Some(next_idx);- if let Some(sug) = self.state.search_suggestions.get(next_idx) {- self.state.search_query = sug.clone();- self.state.last_suggest_query = self.state.search_query.trim().to_string();- }}_ => {}},diff --git a/src/tui/app/requests.rs b/src/tui/app/requests.rsindex ad190ef..5e8dbd4 100644--- a/src/tui/app/requests.rs+++ b/src/tui/app/requests.rs@@ -13,21 +13,25 @@ impl App {self.state.active_suggest_request.wrapping_add(1);let request_id = self.state.active_suggest_request;if query.starts_with('/') {- let mut commands = vec![- "/clear-cache",- "/update",- "/toggle-update",- "/github",- "/theme",- "/enable-bdix",- "/disable-bdix",- ];+ let mut commands = Vec::new();if self.state.is_tv_mode {commands.push("/list");commands.push("/config");} else {- commands.extend(vec!["/browse", "/history"]);+ commands.push("/browse");+ commands.push("/history");}+ commands.push("/theme");+ commands.push("/update");+ commands.push("/toggle-update");+ commands.push("/clear-cache");+ commands.push("/github");+ if self.state.bdix_enabled {+ commands.push("/disable-bdix");+ } else {+ commands.push("/enable-bdix");+ }+let mut suggestions = vec![];for cmd in commands {if cmd.starts_with(&query) {@@ -71,7 +75,10 @@ impl App {if request_id != self.state.active_suggest_request {return None;}- if self.state.is_tv_mode || self.state.active_provider != ProviderKind::MovieBox {+ if !query.starts_with('/')+ && (self.state.is_tv_mode+ || self.state.active_provider != ProviderKind::MovieBox)+ {return None;}if self.state.suggest_index.is_some() {@@ -93,7 +100,8 @@ impl App {.and_then(|s| s.as_array());if let Some(subjects) = subjects_opt {- for item in subjects.iter().take(8) {+ let limit = if query.starts_with('/') { 20 } else { 10 };+ for item in subjects.iter().take(limit) {let raw_title = item.get("title").and_then(|t| t.as_str())@@ -106,6 +114,15 @@ impl App {.trim().to_string();+ if query.starts_with('/') {+ if clean_title.starts_with(&query)+ && !self.state.search_suggestions.contains(&clean_title)+ {+ self.state.search_suggestions.push(clean_title);+ }+ continue;+ }+let normalized_query = query.to_lowercase().replace(|c: char| !c.is_alphanumeric(), "");diff --git a/src/tui/app/system.rs b/src/tui/app/system.rsindex 32d6137..c6629a9 100644--- a/src/tui/app/system.rs+++ b/src/tui/app/system.rs@@ -39,7 +39,7 @@ impl App {{self.state.last_suggest_query = current_query.clone();if !current_query.is_empty() {- if self.state.is_tv_mode {+ if self.state.is_tv_mode && !current_query.starts_with('/') {let q = current_query.to_lowercase();self.state.search_suggestions = self.statediff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rsindex 2e856ed..e20d440 100644--- a/src/tui/screens/home.rs+++ b/src/tui/screens/home.rs@@ -871,7 +871,7 @@ pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme)let position = state.suggest_index.map(|index| format!("{}/{}", index + 1, state.search_suggestions.len()))- .unwrap_or_else(|| state.search_suggestions.len().to_string());+ .unwrap_or_else(|| format!("{} available", state.search_suggestions.len()));let heading = Line::from(vec![Span::styled(" Suggestions", theme.title),Span::styled(" · ", theme.overlay0),