canvas now working properly well

This commit is contained in:
filipriec
2025-04-17 15:40:07 +02:00
parent e921862a7f
commit ff8b4eb0f6
4 changed files with 38 additions and 21 deletions

View File

@@ -198,31 +198,32 @@ pub fn handle_add_table_navigation(
add_table_state.current_focus = new_focus;
*command_message = format!("Focus set to {:?}", add_table_state.current_focus);
// --- THIS IS THE KEY PART ---
// Check if the *new* focus target is one of the canvas input fields
let new_is_canvas_input_focus = matches!(new_focus,
AddTableFocus::InputTableName | AddTableFocus::InputColumnName | AddTableFocus::InputColumnType
);
app_state.ui.focus_outside_canvas = !new_is_canvas_input_focus;
// Set focus_outside_canvas based on whether the new focus is NOT an input field
app_state.ui.focus_outside_canvas = !new_is_canvas_input_focus; // <--- Sets the flag correctly
// --- END KEY PART ---
// Select first item when focusing a table
match add_table_state.current_focus {
AddTableFocus::ColumnsTable if add_table_state.column_table_state.selected().is_none() && !add_table_state.columns.is_empty() => {
add_table_state.column_table_state.select(Some(0));
add_table_state.column_table_state.select(Some(0));
}
AddTableFocus::IndexesTable if add_table_state.index_table_state.selected().is_none() && !add_table_state.indexes.is_empty() => {
add_table_state.index_table_state.select(Some(0));
add_table_state.index_table_state.select(Some(0));
}
AddTableFocus::LinksTable if add_table_state.link_table_state.selected().is_none() && !add_table_state.links.is_empty() => {
add_table_state.link_table_state.select(Some(0));
}
_ => {}
AddTableFocus::LinksTable if add_table_state.link_table_state.selected().is_none() && !add_table_state.links.is_empty() => {
add_table_state.link_table_state.select(Some(0));
}_ => {}
}
} else if !handled {
// If not handled by this specific navigation, clear the message potentially set by get_general_action
// command_message.clear(); // Optional: depends if you want default messages
// ...
}
handled
}

View File

@@ -14,7 +14,7 @@ use crate::state::app::buffer::BufferState;
pub fn handle_admin_navigation(
key: KeyEvent,
config: &Config,
app_state: &AppState,
app_state: &mut AppState,
admin_state: &mut AdminState,
buffer_state: &mut BufferState,
command_message: &mut String,
@@ -161,6 +161,7 @@ pub fn handle_admin_navigation(
}
AdminFocus::Button2 => {
buffer_state.update_history(AppView::AddTable);
app_state.ui.focus_outside_canvas = false;
*command_message = "Navigating to Add Table page...".to_string();
}
AdminFocus::Button3 => {

View File

@@ -79,21 +79,36 @@ pub async fn execute_action(
match action {
"move_up" => {
key_sequence_tracker.reset();
let num_fields = AddTableState::INPUT_FIELD_COUNT; // Use the constant
let num_fields = AddTableState::INPUT_FIELD_COUNT;
if num_fields == 0 { return Ok("No fields.".to_string()); }
let current_field = state.current_field();
let current_field = state.current_field(); // Gets the index (0, 1, or 2)
if current_field > 0 {
// This handles moving from field 2 -> 1, or 1 -> 0
let new_field = current_field - 1;
state.set_current_field(new_field);
let current_input = state.get_current_input();
let max_cursor_pos = current_input.len(); // Allow cursor at end
let new_pos = (*ideal_cursor_column).min(max_cursor_pos);
state.set_current_cursor_pos(new_pos);
// ... (rest of the logic to set cursor position) ...
} else {
// Optionally move focus outside canvas when moving up from the first field
// app_state.ui.focus_outside_canvas = true;
// return Ok("Focus moved above canvas".to_string());
// --- THIS IS WHERE THE FIX GOES ---
// current_field is 0 (InputTableName), and user pressed Up.
// We need to move focus *outside* the canvas.
// Set the flag to indicate focus is leaving the canvas
app_state.ui.focus_outside_canvas = true;
// Decide which element gets focus. Based on your layout and the
// downward navigation (CancelButton wraps to InputTableName),
// moving up from InputTableName should likely go to CancelButton.
state.current_focus = crate::state::pages::add_table::AddTableFocus::CancelButton;
// Reset the sequence tracker as the action is complete
key_sequence_tracker.reset();
// Return a message indicating the focus change
return Ok("Focus moved above canvas".to_string());
// --- END FIX ---
}
// If we moved within the canvas (e.g., 1 -> 0), return empty string
Ok("".to_string())
}
"move_down" => {

View File

@@ -27,7 +27,7 @@ impl ModeManager {
return AppMode::Highlight;
}
if app_state.ui.focus_outside_canvas || app_state.ui.show_add_table{
if app_state.ui.focus_outside_canvas {
return AppMode::General;
}