working autocomplete, need more fixes soon

This commit is contained in:
filipriec
2025-05-26 11:54:28 +02:00
parent 116db3566f
commit 3463a52960
3 changed files with 346 additions and 25 deletions

View File

@@ -14,15 +14,14 @@ use ratatui::{
use crate::components::handlers::canvas::render_canvas;
use crate::components::common::{dialog, autocomplete}; // Added autocomplete
use crate::config::binds::config::EditorKeybindingMode;
use crate::modes::handlers::mode_manager::AppMode; // For checking AppMode::Edit
pub fn render_add_logic(
f: &mut Frame,
area: Rect,
theme: &Theme,
app_state: &AppState,
add_logic_state: &mut AddLogicState, // Changed to &mut
is_edit_mode: bool, // This is the general edit mode from EventHandler
add_logic_state: &mut AddLogicState,
is_edit_mode: bool,
highlight_state: &HighlightState,
) {
let main_block = Block::default()
@@ -47,13 +46,10 @@ pub fn render_add_logic(
let script_title_hint = match add_logic_state.editor_keybinding_mode {
EditorKeybindingMode::Vim => {
let vim_mode_status = crate::components::common::text_editor::TextEditor::get_vim_mode_status(&add_logic_state.vim_state);
// Vim mode status is relevant regardless of the general `is_edit_mode`
format!("Script {}", vim_mode_status)
}
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
// For default/emacs, the general `is_edit_mode` (passed to this function)
// indicates if the text area itself is in an "editing" state.
if is_edit_mode { // This `is_edit_mode` refers to the text area's active editing.
if is_edit_mode {
"Script (Editing)".to_string()
} else {
"Script".to_string()
@@ -70,7 +66,46 @@ pub fn render_add_logic(
.border_style(border_style),
);
f.render_widget(&*editor_ref, inner_area);
return;
// Drop the editor borrow before accessing autocomplete state
drop(editor_ref);
// === SCRIPT EDITOR AUTOCOMPLETE RENDERING ===
if add_logic_state.script_editor_autocomplete_active && !add_logic_state.script_editor_suggestions.is_empty() {
if let Some((trigger_line, trigger_col)) = add_logic_state.script_editor_trigger_position {
// For now, we'll position the autocomplete at a simple offset from the trigger
// Since we can't easily get viewport info, we'll position it relatively
// This is a simplified approach - in a real implementation you'd want proper viewport tracking
// Account for TextArea's block borders (1 for each side)
let block_offset_x = 1;
let block_offset_y = 1;
// Simple positioning: assume trigger is visible and use direct coordinates
// This works for small scripts but may need improvement for larger ones
let visible_line = trigger_line;
let visible_col = trigger_col + 1 + add_logic_state.script_editor_filter_text.len();
let input_rect = Rect {
x: (inner_area.x + block_offset_x + visible_col as u16).min(inner_area.right().saturating_sub(20)),
y: (inner_area.y + block_offset_y + visible_line as u16 + 1).min(inner_area.bottom().saturating_sub(5)),
width: 1, // Minimum width for positioning
height: 1,
};
// Render autocomplete dropdown
autocomplete::render_autocomplete_dropdown(
f,
input_rect,
f.area(), // Full frame area for clamping
theme,
&add_logic_state.script_editor_suggestions,
add_logic_state.script_editor_selected_suggestion_index,
);
}
}
return; // Exit early for fullscreen mode
}
// Regular layout with preview