navigation in the menu but needs refactoring

This commit is contained in:
filipriec
2025-05-29 16:11:41 +02:00
parent 799d8471c9
commit 668eeee197
7 changed files with 329 additions and 118 deletions

View File

@@ -14,9 +14,9 @@ use crate::components::{
};
use crate::config::colors::themes::Theme;
use ratatui::{
layout::{Constraint, Direction, Layout, Rect}, // Added Rect
style::Style, // Added Style for render_find_file_palette
widgets::{Block, List, ListItem, Paragraph}, // Added for render_find_file_palette
layout::{Constraint, Direction, Layout, Rect},
style::Style,
widgets::{Block, List, ListItem, Paragraph},
Frame,
};
use crate::state::pages::canvas_state::CanvasState;
@@ -29,6 +29,7 @@ use crate::state::app::buffer::BufferState;
use crate::state::app::state::AppState; // AppState is needed for app_state.ui checks
use crate::state::pages::admin::AdminState;
use crate::state::app::highlight::HighlightState;
use crate::modes::general::command_navigation::NavigationState;
// ++ New function to render the Find File Palette ++
fn render_find_file_palette(
@@ -91,11 +92,8 @@ pub fn render_ui(
event_handler_command_input: &str, // For normal command line
event_handler_command_mode_active: bool, // Normal command line active?
event_handler_command_message: &str,
// ++ Find File Palette specific state from EventHandler ++
find_file_palette_active: bool,
find_file_options: &[String],
find_file_selected_index: Option<usize>,
find_file_palette_input: &str, // Input for the palette
// Navigation state replaces find file palette specific state
navigation_state: &NavigationState,
// General app state
total_count: u64,
current_position: u64,
@@ -108,10 +106,10 @@ pub fn render_ui(
// Determine the height needed for the bottom bar (status + command/palette)
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)]; // Status line
let command_palette_area_height = if find_file_palette_active {
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 + find_file_options.iter().take(max_visible_options).count().min(max_visible_options) as u16
1 + navigation_state.filtered_options.iter().take(max_visible_options).count().min(max_visible_options) as u16
} else if event_handler_command_mode_active {
1 // Height for normal command line
} else {
@@ -228,14 +226,14 @@ pub fn render_ui(
// Render Find File Palette OR Normal Command Line
if let Some(area) = command_render_area {
if find_file_palette_active {
if navigation_state.active {
render_find_file_palette(
f,
area,
theme,
find_file_palette_input, // Pass palette-specific input
find_file_options,
find_file_selected_index,
&navigation_state.input,
&navigation_state.filtered_options.iter().map(|(_, opt)| opt.clone()).collect::<Vec<_>>(),
navigation_state.selected_index,
);
} else if event_handler_command_mode_active {
// Normal command line
@@ -243,10 +241,9 @@ pub fn render_ui(
f,
area,
event_handler_command_input,
true, // It's active
true,
theme,
event_handler_command_message,
// No palette-specific args for normal command line
);
}
}

View File

@@ -209,16 +209,12 @@ pub async fn run_ui() -> Result<()> {
&mut admin_state,
&buffer_state,
&theme,
event_handler.is_edit_mode, // is_event_handler_edit_mode
event_handler.is_edit_mode,
&event_handler.highlight_state,
&event_handler.command_input, // event_handler_command_input
event_handler.command_mode, // event_handler_command_mode_active
&event_handler.command_message, // event_handler_command_message
// Find File Palette specific state
event_handler.find_file_palette_active,
&event_handler.find_file_options,
event_handler.find_file_selected_index,
&event_handler.find_file_input,
&event_handler.command_input,
event_handler.command_mode,
&event_handler.command_message,
&event_handler.navigation_state,
// General app state
app_state.total_count,
app_state.current_position,