Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(ui): Wrap search suggestions in elevated opaque card to prevent grid bleed

Samir Hossainse4be68512d07
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fa529c3..55370b2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,7 @@
## [Unreleased]
### Fixed
+- **Search Suggestions Overlay Bleed**: Wrapped search suggestions in an elevated, bordered card with opaque background clearing (`theme.surface0`), and gated terminal graphics poster rendering while typing suggestions, eliminating text and image collisions over background search results.
- **Season Download Stream Error Recovery**: Prevented download queue stalls when resolving individual episode stream URLs fails; failed streams report diagnostics and allow the remaining queue to continue.
- **Favorites & Watch History Corruption Recovery**: Corrupted JSON configuration and history state files now rotate to `.corrupt` backups instead of hard deletion, preserving recoverable user data.
- **Details Screen Hit-Testing & Selector Alignment**: Aligned mouse hit-testing regions and season/episode selector column geometry across all compact, medium, and wide terminal tiers.
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index e29d251..559df4e 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -457,15 +457,25 @@ impl App {
.saturating_sub(visible_count),
);
- let start_y = search_bar_area.bottom();
- let container_w = search_bar_area.width.max(48);
- let container_x = search_bar_area.x;
- if col >= container_x
- && col < container_x + container_w
- && row >= start_y
- && (row - start_y) < visible_count as u16
+ let visible_slice_len = self
+ .state
+ .search_suggestions
+ .len()
+ .saturating_sub(suggestion_offset)
+ .min(visible_count);
+
+ let (container_area, inner_area) = crate::tui::screens::home::search_suggestions_bounds(
+ area,
+ search_bar_area,
+ visible_slice_len,
+ );
+
+ if col >= inner_area.left()
+ && col < inner_area.right()
+ && row >= inner_area.top()
+ && row < inner_area.bottom()
{
- let clicked_idx = suggestion_offset + (row - start_y) as usize;
+ let clicked_idx = suggestion_offset + (row - inner_area.top()) as usize;
if let Some(query) = self.state.search_suggestions.get(clicked_idx).cloned() {
self.action_sender
.send(Action::SelectSuggestion { query })
@@ -473,6 +483,14 @@ impl App {
}
return None;
}
+
+ if col >= container_area.left()
+ && col < container_area.right()
+ && row >= container_area.top()
+ && row < container_area.bottom()
+ {
+ return None;
+ }
}
if row >= search_bar_area.y && row < search_bar_area.y + search_bar_area.height {
diff --git a/src/tui/screens/home.rs b/src/tui/screens/home.rs
index 05066d2..3298fe0 100644
--- a/src/tui/screens/home.rs
+++ b/src/tui/screens/home.rs
@@ -7,7 +7,7 @@ use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Color, Modifier, Style},
text::{Line, Span},
- widgets::{Block, Cell, Paragraph, Row, Table},
+ widgets::{Block, Borders, Cell, Paragraph, Row, Table},
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
@@ -511,6 +511,7 @@ fn render_favorites_landing(frame: &mut Frame, area: Rect, state: &AppState, the
}
}
+#[cfg(test)]
fn search_content(
state: &AppState,
view: SearchViewState,
@@ -1833,13 +1834,45 @@ fn suggestion_source_badge<'a>(
}
}
+pub fn search_suggestions_bounds(area: Rect, search_bar_area: Rect, count: usize) -> (Rect, Rect) {
+ if count == 0 || search_bar_area.width == 0 {
+ return (Rect::default(), Rect::default());
+ }
+
+ let start_y = search_bar_area.bottom();
+ let max_h = area.bottom().saturating_sub(start_y);
+ let container_h = ((count as u16).saturating_add(2)).min(max_h);
+
+ let max_w = area
+ .right()
+ .saturating_sub(search_bar_area.x)
+ .saturating_sub(1);
+ let container_w = search_bar_area.width.max(48).min(max_w);
+
+ let container_area = Rect {
+ x: search_bar_area.x,
+ y: start_y,
+ width: container_w,
+ height: container_h,
+ };
+
+ let inner_area = Rect {
+ x: container_area.x.saturating_add(1),
+ y: container_area.y.saturating_add(1),
+ width: container_area.width.saturating_sub(2),
+ height: container_area.height.saturating_sub(2),
+ };
+
+ (container_area, inner_area)
+}
+
fn render_search_suggestions(
frame: &mut Frame,
area: Rect,
search_bar_area: Rect,
state: &AppState,
theme: &Theme,
- view: SearchViewState,
+ _view: SearchViewState,
) {
if state.input_mode != InputMode::Editing
|| state.search_suggestions.is_empty()
@@ -1855,24 +1888,6 @@ fn render_search_suggestions(
.saturating_sub(visible_count)
.min(state.search_suggestions.len().saturating_sub(visible_count));
- let is_centered = state.search_results.is_empty();
-
- let search_text_len = if is_centered {
- let content_sample = search_content(state, view, false, search_bar_area.width, false);
- crate::tui::text::width(&content_sample) as u16
- } else {
- 0
- };
-
- let prompt_x = if is_centered {
- search_bar_area.x + search_bar_area.width.saturating_sub(search_text_len) / 2
- } else {
- search_bar_area.x
- };
-
- let available_width = area.right().saturating_sub(prompt_x).saturating_sub(2);
- let start_y = search_bar_area.bottom();
-
let visible_slice: Vec<(usize, &String)> = state
.search_suggestions
.iter()
@@ -1885,22 +1900,24 @@ fn render_search_suggestions(
return;
}
- let container_h = (visible_slice.len() as u16).min(area.bottom().saturating_sub(start_y));
- let container_w = available_width.min(search_bar_area.width.max(48));
- let container_area = Rect {
- x: prompt_x.saturating_sub(1).max(area.x),
- y: start_y,
- width: container_w.min(area.right().saturating_sub(prompt_x)),
- height: container_h,
- };
+ let (container_area, inner_area) =
+ search_suggestions_bounds(area, search_bar_area, visible_slice.len());
+
+ if container_area.width == 0 || container_area.height <= 2 || inner_area.height == 0 {
+ return;
+ }
crate::tui::clear_area(frame, container_area, theme);
- let container_block = Block::default().style(theme.surface0);
+ let container_block = Block::default()
+ .borders(Borders::ALL)
+ .border_type(crate::tui::overlay::border_type(state.basic_terminal))
+ .border_style(theme.border_focus)
+ .style(Style::default().bg(theme.surface0.fg.unwrap_or(theme.base)));
frame.render_widget(container_block, container_area);
for (row_idx, &(orig_idx, suggestion)) in visible_slice.iter().enumerate() {
- let current_y = start_y + row_idx as u16;
- if current_y >= area.bottom() {
+ let current_y = inner_area.y + row_idx as u16;
+ if current_y >= inner_area.bottom() {
break;
}
@@ -1929,6 +1946,13 @@ fn render_search_suggestions(
let desc = slash_command_description(suggestion, state);
+ let row_bg = if is_selected {
+ theme.surface1.fg.unwrap_or(theme.base)
+ } else {
+ theme.surface0.fg.unwrap_or(theme.base)
+ };
+ let row_style = Style::default().bg(row_bg);
+
let branch_style = if is_selected {
theme.lavender.add_modifier(Modifier::BOLD)
} else {
@@ -1960,23 +1984,25 @@ fn render_search_suggestions(
let name_len = crate::tui::text::width(display_name) + badge_width;
let pad = 28usize.saturating_sub(name_len).max(2);
spans.push(Span::raw(" ".repeat(pad)));
- let desc_budget = (available_width as usize)
- .saturating_sub(3 + name_len + pad)
- .max(6);
- spans.push(Span::styled(
- crate::tui::text::truncate_width(description, desc_budget),
- desc_style,
- ));
+ let branch_width = crate::tui::text::width(branch_symbol);
+ let desc_budget =
+ (inner_area.width as usize).saturating_sub(branch_width + name_len + pad);
+ if desc_budget > 0 {
+ spans.push(Span::styled(
+ crate::tui::text::truncate_width(description, desc_budget),
+ desc_style,
+ ));
+ }
}
let row_area = Rect {
- x: prompt_x,
+ x: inner_area.x,
y: current_y,
- width: available_width,
+ width: inner_area.width,
height: 1,
};
- frame.render_widget(Paragraph::new(Line::from(spans)), row_area);
+ frame.render_widget(Paragraph::new(Line::from(spans)).style(row_style), row_area);
}
}
@@ -2033,6 +2059,36 @@ mod tests {
);
})
.unwrap();
+
+ let buffer = terminal.backend().buffer();
+ let mut rendered = String::new();
+ for y in 0..24 {
+ for x in 0..80 {
+ rendered.push_str(buffer[(x, y)].symbol());
+ }
+ rendered.push('\n');
+ }
+ assert!(rendered.contains("help"));
+ assert!(rendered.contains("history"));
+ assert!(rendered.contains("Inception"));
+ assert!(rendered.contains("[CMD]"));
+ assert!(rendered.contains("[HISTORY]"));
+ assert!(rendered.contains("[SUGGEST]"));
+ }
+
+ #[test]
+ fn test_search_suggestions_bounds() {
+ let area = Rect::new(0, 0, 80, 24);
+ let search_bar = Rect::new(10, 2, 60, 3);
+ let (container, inner) = search_suggestions_bounds(area, search_bar, 3);
+ assert_eq!(container.x, 10);
+ assert_eq!(container.y, 5);
+ assert_eq!(container.width, 60);
+ assert_eq!(container.height, 5);
+ assert_eq!(inner.x, 11);
+ assert_eq!(inner.y, 6);
+ assert_eq!(inner.width, 58);
+ assert_eq!(inner.height, 3);
}
#[test]
diff --git a/src/tui/state.rs b/src/tui/state.rs
index d001610..4bf7194 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -544,6 +544,7 @@ impl AppState {
|| self.show_season_download_confirm
|| self.show_episode_download_confirm
|| self.update_available.is_some()
+ || (self.input_mode == InputMode::Editing && !self.search_suggestions.is_empty())
}
pub fn clear_search_state(&mut self) {
@@ -809,6 +810,13 @@ mod tests {
assert!(state.has_active_modal());
state.update_available = None;
+ state.input_mode = InputMode::Editing;
+ state.search_suggestions = vec!["suggestion".to_string()];
+ assert!(state.has_active_modal());
+ state.search_suggestions.clear();
+ assert!(!state.has_active_modal());
+ state.input_mode = InputMode::Normal;
+
assert!(!state.has_active_modal());
}
}
diff --git a/tests/tui_acceptance.rs b/tests/tui_acceptance.rs
index 7be5e40..a298ed2 100644
--- a/tests/tui_acceptance.rs
+++ b/tests/tui_acceptance.rs
@@ -190,6 +190,31 @@ async fn test_mouse_click_search_input_mode() {
let _ = app.state().input_mode;
}
+#[tokio::test]
+async fn test_mouse_click_search_suggestion_selects_query() {
+ let mut app = App::new();
+ app.state_mut().input_mode = InputMode::Editing;
+ app.state_mut().search_suggestions = vec![
+ "Deewaniyat".to_string(),
+ "Ek Deewane Ki Deewaniyat".to_string(),
+ ];
+
+ let area = ratatui::layout::Rect::new(0, 0, 80, 24);
+ let search_bar_area = ratatui::layout::Rect::new(10, 5, 60, 3);
+ let (_container, inner) =
+ moviebox_tui::tui::screens::home::search_suggestions_bounds(area, search_bar_area, 2);
+
+ app.handle_action(Action::MouseClick(inner.x, inner.y))
+ .await;
+ app.handle_action(Action::SelectSuggestion {
+ query: "Deewaniyat".to_string(),
+ })
+ .await;
+ assert_eq!(app.state().search_query.as_str(), "Deewaniyat");
+ assert_eq!(app.state().input_mode, InputMode::Normal);
+ assert!(app.state().search_suggestions.is_empty());
+}
+
#[tokio::test]
async fn test_mouse_scroll_maps_to_key_actions() {
let mut app = App::new();