fixed height of the find file
This commit is contained in:
@@ -31,6 +31,8 @@ use crate::state::pages::admin::AdminState;
|
|||||||
use crate::state::app::highlight::HighlightState;
|
use crate::state::app::highlight::HighlightState;
|
||||||
use crate::modes::general::command_navigation::NavigationState;
|
use crate::modes::general::command_navigation::NavigationState;
|
||||||
|
|
||||||
|
const PALETTE_MAX_VISIBLE_OPTIONS: usize = 15;
|
||||||
|
|
||||||
// ++ New function to render the Find File Palette ++
|
// ++ New function to render the Find File Palette ++
|
||||||
fn render_find_file_palette(
|
fn render_find_file_palette(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
@@ -40,11 +42,36 @@ fn render_find_file_palette(
|
|||||||
options: &[String],
|
options: &[String],
|
||||||
selected_index: Option<usize>,
|
selected_index: Option<usize>,
|
||||||
) {
|
) {
|
||||||
|
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()
|
let chunks = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(1), // For palette input line
|
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);
|
.split(area);
|
||||||
|
|
||||||
@@ -55,12 +82,13 @@ fn render_find_file_palette(
|
|||||||
f.render_widget(input_paragraph, chunks[0]);
|
f.render_widget(input_paragraph, chunks[0]);
|
||||||
|
|
||||||
// Draw the list of options
|
// Draw the list of options
|
||||||
if !options.is_empty() && chunks.len() > 1 {
|
if !visible_options_slice.is_empty() && chunks.len() > 1 {
|
||||||
let list_items: Vec<ListItem> = options
|
let list_items: Vec<ListItem> = visible_options_slice
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(idx, opt_str)| {
|
.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
|
Style::default().fg(theme.bg).bg(theme.accent) // Highlight selected
|
||||||
} else {
|
} else {
|
||||||
Style::default().fg(theme.fg).bg(theme.bg)
|
Style::default().fg(theme.fg).bg(theme.bg)
|
||||||
@@ -107,9 +135,7 @@ pub fn render_ui(
|
|||||||
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)]; // Status line
|
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)]; // Status line
|
||||||
|
|
||||||
let command_palette_area_height = if navigation_state.active {
|
let command_palette_area_height = if navigation_state.active {
|
||||||
// Height for palette: 1 for input + number of visible options
|
1 + PALETTE_MAX_VISIBLE_OPTIONS as u16
|
||||||
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
|
|
||||||
} else if event_handler_command_mode_active {
|
} else if event_handler_command_mode_active {
|
||||||
1 // Height for normal command line
|
1 // Height for normal command line
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user