autocomplete is now powerful
This commit is contained in:
@@ -11,6 +11,7 @@ use crate::services::GrpcClient;
|
||||
use tokio::sync::mpsc;
|
||||
use anyhow::Result;
|
||||
use crate::components::common::text_editor::TextEditor;
|
||||
use crate::services::ui_service::UiService;
|
||||
|
||||
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
|
||||
|
||||
@@ -21,8 +22,8 @@ pub fn handle_add_logic_navigation(
|
||||
add_logic_state: &mut AddLogicState,
|
||||
is_edit_mode: &mut bool,
|
||||
buffer_state: &mut BufferState,
|
||||
_grpc_client: GrpcClient,
|
||||
_save_logic_sender: SaveLogicResultSender,
|
||||
grpc_client: GrpcClient,
|
||||
save_logic_sender: SaveLogicResultSender,
|
||||
command_message: &mut String,
|
||||
) -> bool {
|
||||
// === FULLSCREEN SCRIPT EDITING - COMPLETE ISOLATION ===
|
||||
@@ -134,11 +135,14 @@ pub fn handle_add_logic_navigation(
|
||||
let trigger_pos = add_logic_state.script_editor_trigger_position;
|
||||
let filter_len = add_logic_state.script_editor_filter_text.len();
|
||||
|
||||
// Deactivate autocomplete first
|
||||
// Check if this is a table name selection
|
||||
let is_table_selection = add_logic_state.is_table_name_suggestion(&suggestion);
|
||||
|
||||
// Deactivate current autocomplete first
|
||||
add_logic_state.deactivate_script_editor_autocomplete();
|
||||
add_logic_state.has_unsaved_changes = true;
|
||||
|
||||
// Then replace text
|
||||
// Replace text in editor
|
||||
if let Some(pos) = trigger_pos {
|
||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
||||
replace_autocomplete_text(
|
||||
@@ -147,9 +151,43 @@ pub fn handle_add_logic_navigation(
|
||||
filter_len,
|
||||
&suggestion,
|
||||
);
|
||||
}
|
||||
|
||||
*command_message = format!("Inserted: {}", suggestion);
|
||||
// If it's a table selection, append "." and trigger column autocomplete
|
||||
if is_table_selection {
|
||||
editor_borrow.insert_str(".");
|
||||
|
||||
// Get the new cursor position (after table name and dot)
|
||||
let new_cursor = editor_borrow.cursor();
|
||||
drop(editor_borrow); // Release the borrow
|
||||
|
||||
// Set up for column autocomplete
|
||||
add_logic_state.script_editor_trigger_position = Some(new_cursor);
|
||||
add_logic_state.script_editor_autocomplete_active = true;
|
||||
add_logic_state.script_editor_filter_text.clear();
|
||||
add_logic_state.trigger_column_autocomplete_for_table(suggestion.clone());
|
||||
|
||||
// Initiate async column fetch
|
||||
let profile_name = add_logic_state.profile_name.clone();
|
||||
let table_name = suggestion.clone();
|
||||
let mut client_clone = grpc_client.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
match UiService::fetch_columns_for_table(&mut client_clone, &profile_name, &table_name).await {
|
||||
Ok(columns) => {
|
||||
// Note: In a real implementation, you'd need to send this back to the main thread
|
||||
// For now, we'll handle this synchronously in the main thread
|
||||
}
|
||||
Err(e) => {
|
||||
tracing::error!("Failed to fetch columns for {}.{}: {}", profile_name, table_name, e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
*command_message = format!("Selected table '{}', fetching columns...", suggestion);
|
||||
} else {
|
||||
*command_message = format!("Inserted: {}", suggestion);
|
||||
}
|
||||
}
|
||||
return true; // Consume the key
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user