From 6bfef1c7a02a3c777cda2975a3136d826b8a7c59 Mon Sep 17 00:00:00 2001 From: filipriec Date: Fri, 18 Apr 2025 10:37:52 +0200 Subject: [PATCH] exit in the general mode is on esc and select is not escaping in the add_table anymore --- client/config.toml | 1 + client/src/components/admin/add_table.rs | 60 ++++++++++++++----- .../modes/navigation/add_table_nav.rs | 40 +++++++++++-- 3 files changed, 81 insertions(+), 20 deletions(-) diff --git a/client/config.toml b/client/config.toml index 43b7e16..f8a904b 100644 --- a/client/config.toml +++ b/client/config.toml @@ -15,6 +15,7 @@ toggle_sidebar = ["ctrl+t"] toggle_buffer_list = ["ctrl+b"] next_field = ["Tab"] prev_field = ["Shift+Tab"] +exit_table_scroll = ["esc"] [keybindings.common] save = ["ctrl+s"] diff --git a/client/src/components/admin/add_table.rs b/client/src/components/admin/add_table.rs index 5b4b664..8df8a96 100644 --- a/client/src/components/admin/add_table.rs +++ b/client/src/components/admin/add_table.rs @@ -271,22 +271,50 @@ pub fn render_add_table( }; // --- Add Button Rendering --- - let add_button = Paragraph::new(" Add ") - .style(get_button_style( - AddTableFocus::AddColumnButton, - add_table_state.current_focus, - )) - .alignment(Alignment::Center) - .block( - Block::default() - .borders(Borders::ALL) - .border_type(BorderType::Rounded) - .border_style(get_button_border_style( - AddTableFocus::AddColumnButton, - add_table_state.current_focus, - )), - ); - f.render_widget(add_button, add_button_area); + let is_add_button_focused = + add_table_state.current_focus == AddTableFocus::AddColumnButton; + + // 1. Define the block with ONLY border styling (no background here) + let add_button_block = Block::default() + .borders(Borders::ALL) + .border_type(BorderType::Rounded) + .border_style(if is_add_button_focused { + Style::default().fg(theme.highlight) // Highlighted border + } else { + Style::default().fg(theme.secondary) // Normal border + }); + // DO NOT add .style(Style::default().bg(...)) here + + // 2. Render the border block first + // Need to clone the block because inner() consumes it + let inner_add_button_area = add_button_block.clone().inner(add_button_area); + f.render_widget(add_button_block, add_button_area); + + // 3. If focused, render a background fill widget INSIDE the inner area + if is_add_button_focused { + let background_fill = Block::default() // Or Paragraph::new("") + .style(Style::default().bg(theme.highlight)); + f.render_widget(background_fill, inner_add_button_area); + } + + // 4. Define the paragraph text style (FG color and bold only) + let mut add_button_text_style = Style::default().fg(if is_add_button_focused { + theme.bg // Reversed text color for contrast on highlight bg + } else { + theme.secondary // Normal text color + }); + + if is_add_button_focused { + add_button_text_style = add_button_text_style.add_modifier(Modifier::BOLD); + } + + let add_button_paragraph = Paragraph::new(" Add ") + .style(add_button_text_style) // Style without BG + .alignment(Alignment::Center); + + // 5. Render the text paragraph inside the inner area (on top of the background fill) + f.render_widget(add_button_paragraph, inner_add_button_area); + // --- Indexes Table Rendering --- let indexes_focused = matches!(add_table_state.current_focus, AddTableFocus::IndexesTable | AddTableFocus::InsideIndexesTable); diff --git a/client/src/functions/modes/navigation/add_table_nav.rs b/client/src/functions/modes/navigation/add_table_nav.rs index 7ef4871..bffdce6 100644 --- a/client/src/functions/modes/navigation/add_table_nav.rs +++ b/client/src/functions/modes/navigation/add_table_nav.rs @@ -37,6 +37,30 @@ pub fn handle_add_table_navigation( ); match action.as_deref() { + // --- Handle Exiting Table Scroll Mode --- + Some("exit_table_scroll") => { + match current_focus { + AddTableFocus::InsideColumnsTable => { + new_focus = AddTableFocus::ColumnsTable; + *command_message = "Exited Columns Table".to_string(); + } + AddTableFocus::InsideIndexesTable => { + new_focus = AddTableFocus::IndexesTable; + *command_message = "Exited Indexes Table".to_string(); + } + AddTableFocus::InsideLinksTable => { + new_focus = AddTableFocus::LinksTable; + *command_message = "Exited Links Table".to_string(); + } + _ => { + // Action triggered but not applicable in this focus state + handled = false; + } + } + // If handled (i.e., focus changed), handled remains true. + // If not handled, handled becomes false. + } + // --- Vertical Navigation (Up/Down) --- Some("move_up") => { match current_focus { @@ -184,12 +208,20 @@ pub fn handle_add_table_navigation( *command_message = "Entered Links Table (Scroll with Up/Down, Select to toggle/exit)".to_string(); } AddTableFocus::InsideColumnsTable => { - new_focus = AddTableFocus::ColumnsTable; // Exit back to block focus - *command_message = "Exited Columns Table".to_string(); + // Select does nothing here anymore, only Esc exits. + if let Some(index) = add_table_state.column_table_state.selected() { + *command_message = format!("Selected column index {} (Press Esc to exit scroll mode)", index); + } else { + *command_message = "No column selected (Press Esc to exit scroll mode)".to_string(); + } } AddTableFocus::InsideIndexesTable => { - new_focus = AddTableFocus::IndexesTable; // Exit back to block focus - *command_message = "Exited Indexes Table".to_string(); + // Select does nothing here anymore, only Esc exits. + if let Some(index) = add_table_state.index_table_state.selected() { + *command_message = format!("Selected index index {} (Press Esc to exit scroll mode)", index); + } else { + *command_message = "No index selected (Press Esc to exit scroll mode)".to_string(); + } } AddTableFocus::InsideLinksTable => { // Toggle selection when pressing select *inside* the links table