automcomplete running and working now
This commit is contained in:
@@ -12,8 +12,8 @@ pub enum AddLogicFocus {
|
||||
InputLogicName,
|
||||
InputTargetColumn,
|
||||
InputDescription,
|
||||
ScriptContentPreview, // Like ColumnsTable - can be highlighted/selected
|
||||
InsideScriptContent, // Like InsideColumnsTable - full editing mode
|
||||
ScriptContentPreview,
|
||||
InsideScriptContent,
|
||||
SaveButton,
|
||||
CancelButton,
|
||||
}
|
||||
@@ -35,6 +35,13 @@ pub struct AddLogicState {
|
||||
pub has_unsaved_changes: bool,
|
||||
pub editor_keybinding_mode: EditorKeybindingMode,
|
||||
pub vim_state: VimState,
|
||||
|
||||
// New fields for Target Column Autocomplete
|
||||
pub table_columns_for_suggestions: Vec<String>, // All columns for the table
|
||||
pub target_column_suggestions: Vec<String>, // Filtered suggestions
|
||||
pub show_target_column_suggestions: bool,
|
||||
pub selected_target_column_suggestion_index: Option<usize>,
|
||||
pub in_target_column_suggestion_mode: bool,
|
||||
}
|
||||
|
||||
impl AddLogicState {
|
||||
@@ -56,10 +63,57 @@ impl AddLogicState {
|
||||
has_unsaved_changes: false,
|
||||
editor_keybinding_mode: editor_config.keybinding_mode.clone(),
|
||||
vim_state: VimState::default(),
|
||||
|
||||
table_columns_for_suggestions: Vec::new(),
|
||||
target_column_suggestions: Vec::new(),
|
||||
show_target_column_suggestions: false,
|
||||
selected_target_column_suggestion_index: None,
|
||||
in_target_column_suggestion_mode: false,
|
||||
}
|
||||
}
|
||||
|
||||
pub const INPUT_FIELD_COUNT: usize = 3;
|
||||
|
||||
/// Updates the target_column_suggestions based on current input.
|
||||
pub fn update_target_column_suggestions(&mut self) {
|
||||
let current_input = self.target_column_input.to_lowercase();
|
||||
if self.table_columns_for_suggestions.is_empty() {
|
||||
self.target_column_suggestions.clear();
|
||||
self.show_target_column_suggestions = false;
|
||||
self.selected_target_column_suggestion_index = None;
|
||||
return;
|
||||
}
|
||||
|
||||
if current_input.is_empty() {
|
||||
self.target_column_suggestions = self.table_columns_for_suggestions.clone();
|
||||
} else {
|
||||
self.target_column_suggestions = self
|
||||
.table_columns_for_suggestions
|
||||
.iter()
|
||||
.filter(|name| name.to_lowercase().contains(¤t_input))
|
||||
.cloned()
|
||||
.collect();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
} else {
|
||||
self.selected_target_column_suggestion_index = None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for AddLogicState {
|
||||
@@ -122,21 +176,21 @@ impl CanvasState for AddLogicState {
|
||||
}
|
||||
|
||||
fn set_current_field(&mut self, index: usize) {
|
||||
self.current_focus = match index {
|
||||
0 => {
|
||||
self.last_canvas_field = 0;
|
||||
AddLogicFocus::InputLogicName
|
||||
},
|
||||
1 => {
|
||||
self.last_canvas_field = 1;
|
||||
AddLogicFocus::InputTargetColumn
|
||||
},
|
||||
2 => {
|
||||
self.last_canvas_field = 2;
|
||||
AddLogicFocus::InputDescription
|
||||
},
|
||||
_ => self.current_focus,
|
||||
let new_focus = match index {
|
||||
0 => AddLogicFocus::InputLogicName,
|
||||
1 => AddLogicFocus::InputTargetColumn,
|
||||
2 => AddLogicFocus::InputDescription,
|
||||
_ => return, // Or handle error/default
|
||||
};
|
||||
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;
|
||||
}
|
||||
self.current_focus = new_focus;
|
||||
self.last_canvas_field = index;
|
||||
}
|
||||
}
|
||||
|
||||
fn set_current_cursor_pos(&mut self, pos: usize) {
|
||||
@@ -161,10 +215,24 @@ impl CanvasState for AddLogicState {
|
||||
}
|
||||
|
||||
fn get_suggestions(&self) -> Option<&[String]> {
|
||||
None
|
||||
if self.current_field() == 1 // Target Column field index
|
||||
&& self.in_target_column_suggestion_mode
|
||||
&& self.show_target_column_suggestions
|
||||
{
|
||||
Some(&self.target_column_suggestions)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
fn get_selected_suggestion_index(&self) -> Option<usize> {
|
||||
None
|
||||
if self.current_field() == 1 // Target Column field index
|
||||
&& self.in_target_column_suggestion_mode
|
||||
&& self.show_target_column_suggestions
|
||||
{
|
||||
self.selected_target_column_suggestion_index
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user