completion not working yet

This commit is contained in:
filipriec
2025-04-11 22:54:44 +02:00
parent e145d63ba6
commit 024a0de4af
5 changed files with 90 additions and 30 deletions

View File

@@ -9,6 +9,7 @@ use ratatui::{
};
use crate::config::colors::themes::Theme;
use crate::state::canvas_state::CanvasState;
use crate::components::common::autocomplete;
pub fn render_canvas(
f: &mut Frame,
@@ -56,6 +57,8 @@ pub fn render_canvas(
.constraints(vec![Constraint::Length(1); fields.len()])
.split(input_area);
let mut active_field_input_rect = None;
// Render labels
for (i, field) in fields.iter().enumerate() {
let label = Paragraph::new(Line::from(Span::styled(
@@ -84,9 +87,38 @@ pub fn render_canvas(
f.render_widget(input_display, input_rows[i]);
if is_active {
active_field_input_rect = Some(input_rows[i]);
let cursor_x = input_rows[i].x + form_state.current_cursor_pos() as u16;
let cursor_y = input_rows[i].y;
f.set_cursor_position((cursor_x, cursor_y));
}
}
// --- 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 dropdown area below the active input field
let dropdown_height = (suggestions.len() as u16).min(5) + 2; // Max 5 suggestions + border
let dropdown_area = Rect {
x: input_rect.x,
y: input_rect.y + 1, // Position below the input line
width: input_rect.width.max(20), // Ensure minimum 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);
}
}
}
}