From e9b4b34fb4048dca88892a821395ffb079a93f08 Mon Sep 17 00:00:00 2001 From: filipriec Date: Thu, 29 May 2025 19:02:02 +0200 Subject: [PATCH] fixed height of the find file --- client/src/ui/handlers/render.rs | 40 ++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/client/src/ui/handlers/render.rs b/client/src/ui/handlers/render.rs index 676b8a1..3c8b1e4 100644 --- a/client/src/ui/handlers/render.rs +++ b/client/src/ui/handlers/render.rs @@ -31,6 +31,8 @@ use crate::state::pages::admin::AdminState; use crate::state::app::highlight::HighlightState; use crate::modes::general::command_navigation::NavigationState; +const PALETTE_MAX_VISIBLE_OPTIONS: usize = 15; + // ++ New function to render the Find File Palette ++ fn render_find_file_palette( f: &mut Frame, @@ -40,11 +42,36 @@ fn render_find_file_palette( options: &[String], selected_index: Option, ) { + let num_total_filtered = options.len(); + let current_selected_list_idx = selected_index; + + let mut display_start_offset = 0; + if num_total_filtered > PALETTE_MAX_VISIBLE_OPTIONS { + if let Some(sel_idx) = current_selected_list_idx { + // If selected item is below the current view window + if sel_idx >= display_start_offset + PALETTE_MAX_VISIBLE_OPTIONS { + display_start_offset = sel_idx - PALETTE_MAX_VISIBLE_OPTIONS + 1; + } + // If selected item is above the current view window + else if sel_idx < display_start_offset { + display_start_offset = sel_idx; + } + // Clamp display_start_offset + display_start_offset = display_start_offset + .min(num_total_filtered.saturating_sub(PALETTE_MAX_VISIBLE_OPTIONS)); + } + } + display_start_offset = display_start_offset.max(0); + + let display_end_offset = + (display_start_offset + PALETTE_MAX_VISIBLE_OPTIONS).min(num_total_filtered); + let visible_options_slice = &options[display_start_offset..display_end_offset]; + let chunks = Layout::default() .direction(Direction::Vertical) .constraints([ Constraint::Length(1), // For palette input line - Constraint::Min(0), // For options list + Constraint::Length(PALETTE_MAX_VISIBLE_OPTIONS as u16), // For options list ]) .split(area); @@ -55,12 +82,13 @@ fn render_find_file_palette( f.render_widget(input_paragraph, chunks[0]); // Draw the list of options - if !options.is_empty() && chunks.len() > 1 { - let list_items: Vec = options + if !visible_options_slice.is_empty() && chunks.len() > 1 { + let list_items: Vec = visible_options_slice .iter() .enumerate() .map(|(idx, opt_str)| { - let style = if Some(idx) == selected_index { + let original_list_idx = display_start_offset + idx; + let style = if current_selected_list_idx == Some(original_list_idx) { Style::default().fg(theme.bg).bg(theme.accent) // Highlight selected } else { Style::default().fg(theme.fg).bg(theme.bg) @@ -107,9 +135,7 @@ pub fn render_ui( let mut bottom_area_constraints: Vec = vec![Constraint::Length(1)]; // Status line let command_palette_area_height = if navigation_state.active { - // Height for palette: 1 for input + number of visible options - let max_visible_options = 7; // Example, can be adjusted - 1 + navigation_state.filtered_options.iter().take(max_visible_options).count().min(max_visible_options) as u16 + 1 + PALETTE_MAX_VISIBLE_OPTIONS as u16 } else if event_handler_command_mode_active { 1 // Height for normal command line } else {