tabbing now works perfectly well
This commit is contained in:
@@ -55,8 +55,6 @@ impl TableDependencyGraph {
|
||||
.collect();
|
||||
|
||||
// Sort for consistent order
|
||||
// dependents_map.values_mut().for_each(|deps| deps.sort());
|
||||
// root_tables.sort(); // This was causing an error if root_tables was not mutable. Let's fix it.
|
||||
let mut sorted_root_tables = root_tables;
|
||||
sorted_root_tables.sort();
|
||||
|
||||
@@ -64,7 +62,6 @@ impl TableDependencyGraph {
|
||||
dependents_list.sort();
|
||||
}
|
||||
|
||||
|
||||
Self {
|
||||
all_tables: all_tables_set,
|
||||
dependents_map,
|
||||
@@ -244,6 +241,19 @@ impl NavigationState {
|
||||
.map(|(_, option_str)| option_str.as_str())
|
||||
}
|
||||
|
||||
pub fn autocomplete_selected(&mut self) {
|
||||
if let Some(selected_option_str) = self.get_selected_option_str() {
|
||||
// The current `self.input` is the text being typed for the current segment/filter.
|
||||
// We replace it with the full string of the selected option.
|
||||
self.input = selected_option_str.to_string();
|
||||
|
||||
// After updating the input, we need to re-filter the options.
|
||||
// This will typically result in the filtered_options containing only the
|
||||
// autocompleted item (or items that start with it, if any).
|
||||
self.update_filtered_options();
|
||||
}
|
||||
}
|
||||
|
||||
// Returns the string to display in the input line of the palette
|
||||
pub fn get_display_input(&self) -> String {
|
||||
match self.navigation_type {
|
||||
@@ -276,7 +286,6 @@ impl NavigationState {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Update self.all_options based on current_path (for TableTree)
|
||||
fn update_options_for_path(&mut self) {
|
||||
if let NavigationType::TableTree = self.navigation_type {
|
||||
@@ -351,20 +360,36 @@ pub async fn handle_command_navigation_event(
|
||||
navigation_state.deactivate();
|
||||
Ok(EventOutcome::Ok(message))
|
||||
} else {
|
||||
// If nothing is selected but enter is pressed, maybe try to navigate if input is a valid path part?
|
||||
// For now, just indicate no selection or clear.
|
||||
if navigation_state.navigation_type == NavigationType::TableTree && !navigation_state.input.is_empty() {
|
||||
// Try to commit current input as a path segment
|
||||
let current_input_clone = navigation_state.input.clone();
|
||||
navigation_state.add_char('/'); // This will commit the input if valid
|
||||
// Check if path actually changed or options updated
|
||||
if navigation_state.input.is_empty() && !navigation_state.all_options.is_empty() {
|
||||
// Simulate pressing '/' to commit the current input as a path segment
|
||||
// Store original options count to see if navigation happened
|
||||
let original_options_count = navigation_state.all_options.len();
|
||||
let original_path = navigation_state.current_path.clone();
|
||||
|
||||
navigation_state.add_char('/');
|
||||
|
||||
// Check if path actually changed and new options are loaded
|
||||
if navigation_state.input.is_empty() && // Input cleared after '/'
|
||||
(navigation_state.current_path != original_path || // Path changed
|
||||
navigation_state.all_options.len() != original_options_count || // Options changed
|
||||
!navigation_state.all_options.is_empty()) // Or new options appeared
|
||||
{
|
||||
return Ok(EventOutcome::Ok(format!("Navigated to: {}/", current_input_clone)));
|
||||
} else {
|
||||
// Navigation didn't happen, revert the add_char('/') effect if necessary
|
||||
// This part is tricky, as add_char('/') modifies state.
|
||||
// For simplicity, we'll just say "no valid selection" if it didn't navigate.
|
||||
return Ok(EventOutcome::Ok(format!("Cannot navigate: '{}' is not a valid path segment or has no children.", current_input_clone)));
|
||||
}
|
||||
}
|
||||
Ok(EventOutcome::Ok("No valid selection to confirm".to_string()))
|
||||
}
|
||||
}
|
||||
KeyCode::Tab => {
|
||||
navigation_state.autocomplete_selected();
|
||||
Ok(EventOutcome::Ok(String::new())) // UI will refresh due to state change
|
||||
}
|
||||
KeyCode::Up => {
|
||||
navigation_state.move_up();
|
||||
Ok(EventOutcome::Ok(String::new()))
|
||||
|
||||
Reference in New Issue
Block a user