working suggestions but position is wrong
This commit is contained in:
@@ -10,6 +10,7 @@ use ratatui::{
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::components::common::autocomplete;
|
||||
use crate::components::render_autocomplete_dropdown;
|
||||
|
||||
pub fn render_canvas(
|
||||
f: &mut Frame,
|
||||
@@ -96,32 +97,7 @@ pub fn render_canvas(
|
||||
|
||||
// --- Render Autocomplete Dropdown (if applicable) ---
|
||||
if let Some(suggestions) = form_state.get_suggestions() {
|
||||
if !suggestions.is_empty() {
|
||||
if let Some(input_rect) = active_field_input_rect {
|
||||
let selected_index = form_state.get_selected_suggestion_index();
|
||||
|
||||
// --- Calculate Compact Dropdown Size ---
|
||||
let max_suggestion_width = suggestions.iter().map(|s| s.len()).max().unwrap_or(0) as u16;
|
||||
let dropdown_width = max_suggestion_width.max(10); // Use longest suggestion width, min 10
|
||||
let dropdown_height = (suggestions.len() as u16).min(5); // Height matches suggestion count, max 5
|
||||
// --- End Size Calculation ---
|
||||
let dropdown_area = Rect {
|
||||
x: input_rect.x,
|
||||
y: input_rect.y + 1,
|
||||
width: dropdown_width,
|
||||
height: dropdown_height,
|
||||
};
|
||||
|
||||
// Ensure dropdown doesn't go off screen (simple vertical check)
|
||||
let screen_height = f.size().height;
|
||||
let clamped_dropdown_area = if dropdown_area.bottom() > screen_height {
|
||||
Rect::new(dropdown_area.x, dropdown_area.y.saturating_sub(dropdown_height + 1), dropdown_area.width, dropdown_area.height)
|
||||
} else {
|
||||
dropdown_area
|
||||
};
|
||||
|
||||
autocomplete::render_autocomplete_dropdown(f, clamped_dropdown_area, theme, suggestions, selected_index);
|
||||
}
|
||||
}
|
||||
let selected = form_state.get_selected_suggestion_index();
|
||||
render_autocomplete_dropdown(f, area, theme, suggestions, selected);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user