From ff8b4eb0f6d3b13c784131c315d5ce65f6f58117 Mon Sep 17 00:00:00 2001 From: filipriec Date: Thu, 17 Apr 2025 15:40:07 +0200 Subject: [PATCH] canvas now working properly well --- .../modes/navigation/add_table_nav.rs | 21 ++++++------ .../functions/modes/navigation/admin_nav.rs | 3 +- .../functions/modes/read_only/add_table_ro.rs | 33 ++++++++++++++----- client/src/modes/handlers/mode_manager.rs | 2 +- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/client/src/functions/modes/navigation/add_table_nav.rs b/client/src/functions/modes/navigation/add_table_nav.rs index 184c412..1def714 100644 --- a/client/src/functions/modes/navigation/add_table_nav.rs +++ b/client/src/functions/modes/navigation/add_table_nav.rs @@ -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 } diff --git a/client/src/functions/modes/navigation/admin_nav.rs b/client/src/functions/modes/navigation/admin_nav.rs index b224928..0c5e104 100644 --- a/client/src/functions/modes/navigation/admin_nav.rs +++ b/client/src/functions/modes/navigation/admin_nav.rs @@ -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 => { diff --git a/client/src/functions/modes/read_only/add_table_ro.rs b/client/src/functions/modes/read_only/add_table_ro.rs index af2b252..2b80e6f 100644 --- a/client/src/functions/modes/read_only/add_table_ro.rs +++ b/client/src/functions/modes/read_only/add_table_ro.rs @@ -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" => { diff --git a/client/src/modes/handlers/mode_manager.rs b/client/src/modes/handlers/mode_manager.rs index 3d5131a..a5240c2 100644 --- a/client/src/modes/handlers/mode_manager.rs +++ b/client/src/modes/handlers/mode_manager.rs @@ -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; }