autocomplete is now powerful
This commit is contained in:
@@ -48,8 +48,12 @@ pub struct AddLogicState {
|
||||
pub script_editor_suggestions: Vec<String>,
|
||||
pub script_editor_selected_suggestion_index: Option<usize>,
|
||||
pub script_editor_trigger_position: Option<(usize, usize)>, // (line, column)
|
||||
pub all_table_names: Vec<String>,
|
||||
pub all_table_names: Vec<String>,
|
||||
pub script_editor_filter_text: String,
|
||||
|
||||
// New fields for same-profile table names and column autocomplete
|
||||
pub same_profile_table_names: Vec<String>, // Tables from same profile only
|
||||
pub script_editor_awaiting_column_autocomplete: Option<String>, // Table name waiting for column fetch
|
||||
}
|
||||
|
||||
impl AddLogicState {
|
||||
@@ -78,13 +82,15 @@ impl AddLogicState {
|
||||
selected_target_column_suggestion_index: None,
|
||||
in_target_column_suggestion_mode: false,
|
||||
|
||||
// Script Editor Autocomplete initialization
|
||||
script_editor_autocomplete_active: false,
|
||||
script_editor_suggestions: Vec::new(),
|
||||
script_editor_selected_suggestion_index: None,
|
||||
script_editor_trigger_position: None,
|
||||
all_table_names: Vec::new(),
|
||||
script_editor_filter_text: String::new(),
|
||||
|
||||
same_profile_table_names: Vec::new(),
|
||||
script_editor_awaiting_column_autocomplete: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -113,16 +119,10 @@ impl AddLogicState {
|
||||
|
||||
self.show_target_column_suggestions = !self.target_column_suggestions.is_empty();
|
||||
if self.show_target_column_suggestions {
|
||||
// If suggestions are shown, ensure a selection (usually the first)
|
||||
// or maintain current if it's still valid.
|
||||
if let Some(selected_idx) = self.selected_target_column_suggestion_index {
|
||||
if selected_idx >= self.target_column_suggestions.len() {
|
||||
self.selected_target_column_suggestion_index = Some(0);
|
||||
}
|
||||
// If the previously selected item is no longer in the filtered list, reset.
|
||||
// This is a bit more complex to check perfectly without iterating again.
|
||||
// For now, just ensuring it's within bounds is a good start.
|
||||
// A more robust way would be to check if the string at selected_idx still matches.
|
||||
} else {
|
||||
self.selected_target_column_suggestion_index = Some(0);
|
||||
}
|
||||
@@ -143,8 +143,8 @@ impl AddLogicState {
|
||||
// Add column names from the current table
|
||||
suggestions.extend(self.table_columns_for_suggestions.clone());
|
||||
|
||||
// Add all table names from all profiles
|
||||
suggestions.extend(self.all_table_names.clone());
|
||||
// Add table names from SAME profile only
|
||||
suggestions.extend(self.same_profile_table_names.clone());
|
||||
|
||||
if self.script_editor_filter_text.is_empty() {
|
||||
self.script_editor_suggestions = suggestions;
|
||||
@@ -172,7 +172,6 @@ impl AddLogicState {
|
||||
/// Sets table columns for autocomplete suggestions
|
||||
pub fn set_table_columns(&mut self, columns: Vec<String>) {
|
||||
self.table_columns_for_suggestions = columns.clone();
|
||||
// Also update target column suggestions for the input field
|
||||
if !columns.is_empty() {
|
||||
self.update_target_column_suggestions();
|
||||
}
|
||||
@@ -183,6 +182,47 @@ impl AddLogicState {
|
||||
self.all_table_names = table_names;
|
||||
}
|
||||
|
||||
/// Sets table names from the same profile for autocomplete suggestions
|
||||
pub fn set_same_profile_table_names(&mut self, table_names: Vec<String>) {
|
||||
self.same_profile_table_names = table_names;
|
||||
}
|
||||
|
||||
/// Checks if a suggestion is a table name (for triggering column autocomplete)
|
||||
pub fn is_table_name_suggestion(&self, suggestion: &str) -> bool {
|
||||
if suggestion == "sql" {
|
||||
return false;
|
||||
}
|
||||
|
||||
if let Some(ref current_table) = self.selected_table_name {
|
||||
if suggestion == current_table {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if self.table_columns_for_suggestions.contains(&suggestion.to_string()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self.same_profile_table_names.contains(&suggestion.to_string())
|
||||
}
|
||||
|
||||
/// Triggers waiting for column autocomplete for a specific table
|
||||
pub fn trigger_column_autocomplete_for_table(&mut self, table_name: String) {
|
||||
self.script_editor_awaiting_column_autocomplete = Some(table_name);
|
||||
}
|
||||
|
||||
/// Updates autocomplete with columns for a specific table
|
||||
pub fn set_columns_for_table_autocomplete(&mut self, columns: Vec<String>) {
|
||||
self.script_editor_suggestions = columns;
|
||||
self.script_editor_selected_suggestion_index = if self.script_editor_suggestions.is_empty() {
|
||||
None
|
||||
} else {
|
||||
Some(0)
|
||||
};
|
||||
self.script_editor_autocomplete_active = !self.script_editor_suggestions.is_empty();
|
||||
self.script_editor_awaiting_column_autocomplete = None;
|
||||
}
|
||||
|
||||
/// Deactivates script editor autocomplete and clears related state
|
||||
pub fn deactivate_script_editor_autocomplete(&mut self) {
|
||||
self.script_editor_autocomplete_active = false;
|
||||
@@ -257,10 +297,9 @@ impl CanvasState for AddLogicState {
|
||||
0 => AddLogicFocus::InputLogicName,
|
||||
1 => AddLogicFocus::InputTargetColumn,
|
||||
2 => AddLogicFocus::InputDescription,
|
||||
_ => return, // Or handle error/default
|
||||
_ => return,
|
||||
};
|
||||
if self.current_focus != new_focus {
|
||||
// If changing field, exit suggestion mode for target column
|
||||
if self.current_focus == AddLogicFocus::InputTargetColumn {
|
||||
self.in_target_column_suggestion_mode = false;
|
||||
self.show_target_column_suggestions = false;
|
||||
@@ -276,12 +315,10 @@ impl CanvasState for AddLogicState {
|
||||
self.logic_name_cursor_pos = pos.min(self.logic_name_input.len());
|
||||
}
|
||||
AddLogicFocus::InputTargetColumn => {
|
||||
self.target_column_cursor_pos =
|
||||
pos.min(self.target_column_input.len());
|
||||
self.target_column_cursor_pos = pos.min(self.target_column_input.len());
|
||||
}
|
||||
AddLogicFocus::InputDescription => {
|
||||
self.description_cursor_pos =
|
||||
pos.min(self.description_input.len());
|
||||
self.description_cursor_pos = pos.min(self.description_input.len());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -292,7 +329,7 @@ impl CanvasState for AddLogicState {
|
||||
}
|
||||
|
||||
fn get_suggestions(&self) -> Option<&[String]> {
|
||||
if self.current_field() == 1 // Target Column field index
|
||||
if self.current_field() == 1
|
||||
&& self.in_target_column_suggestion_mode
|
||||
&& self.show_target_column_suggestions
|
||||
{
|
||||
@@ -303,7 +340,7 @@ impl CanvasState for AddLogicState {
|
||||
}
|
||||
|
||||
fn get_selected_suggestion_index(&self) -> Option<usize> {
|
||||
if self.current_field() == 1 // Target Column field index
|
||||
if self.current_field() == 1
|
||||
&& self.in_target_column_suggestion_mode
|
||||
&& self.show_target_column_suggestions
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user