This commit is contained in:
filipriec
2025-08-20 11:33:34 +02:00
parent 2cda54633f
commit 589220a2ba
6 changed files with 11 additions and 62 deletions

View File

@@ -3,8 +3,7 @@ use crate::config::colors::themes::Theme;
use crate::state::app::highlight::HighlightState;
use crate::state::app::state::AppState;
use crate::state::pages::add_logic::{AddLogicFocus, AddLogicState};
use canvas::{render_canvas_default, render_canvas};
use canvas::canvas::HighlightState as CanvasHighlightState;
use canvas::{render_canvas, FormEditor};
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
@@ -15,15 +14,6 @@ use ratatui::{
use crate::components::common::{dialog, autocomplete}; // Added autocomplete
use crate::config::binds::config::EditorKeybindingMode;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
HighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
}
}
pub fn render_add_logic(
f: &mut Frame,
area: Rect,
@@ -31,7 +21,6 @@ pub fn render_add_logic(
app_state: &AppState,
add_logic_state: &mut AddLogicState,
is_edit_mode: bool,
highlight_state: &HighlightState,
) {
let main_block = Block::default()
.title(" Add New Logic Script ")
@@ -169,16 +158,12 @@ pub fn render_add_logic(
| AddLogicFocus::InputDescription
);
let canvas_highlight_state = convert_highlight_state(highlight_state);
let active_field_rect = render_canvas(
f,
canvas_area,
add_logic_state, // will later be wrapped in FormEditor
);
let editor = FormEditor::new(add_logic_state.clone());
let active_field_rect = render_canvas(f, canvas_area, &editor, theme);
// --- Render Autocomplete for Target Column ---
// `is_edit_mode` here refers to the general edit mode of the EventHandler
if is_edit_mode && add_logic_state.current_field() == 1 { // Target Column field
if is_edit_mode && editor.current_field() == 1 { // Target Column field
if add_logic_state.in_target_column_suggestion_mode && add_logic_state.show_target_column_suggestions {
if !add_logic_state.target_column_suggestions.is_empty() {
if let Some(input_rect) = active_field_rect {

View File

@@ -3,8 +3,7 @@ use crate::config::colors::themes::Theme;
use crate::state::app::highlight::HighlightState;
use crate::state::app::state::AppState;
use crate::state::pages::add_table::{AddTableFocus, AddTableState};
use canvas::{render_canvas_default, render_canvas};
use canvas::canvas::HighlightState as CanvasHighlightState;
use canvas::{render_canvas_default, render_canvas, FormEditor};
use ratatui::{
layout::{Alignment, Constraint, Direction, Layout, Rect},
style::{Modifier, Style},
@@ -14,15 +13,6 @@ use ratatui::{
};
use crate::components::common::dialog;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => CanvasHighlightState::Characterwise { anchor: *anchor },
HighlightState::Linewise { anchor_line } => CanvasHighlightState::Linewise { anchor_line: *anchor_line },
}
}
/// Renders the Add New Table page layout, structuring the display of table information,
/// input fields, and action buttons. Adapts layout based on terminal width.
pub fn render_add_table(
@@ -358,12 +348,8 @@ pub fn render_add_table(
);
// --- Canvas Rendering (Column Definition Input) - USING CANVAS LIBRARY ---
let canvas_highlight_state = convert_highlight_state(highlight_state);
let _active_field_rect = render_canvas(
f,
canvas_area,
add_table_state, // will later be wrapped in FormEditor
);
let editor = FormEditor::new(add_table_state.clone());
let _active_field_rect = render_canvas(f, canvas_area, &editor, theme);
// --- Button Style Helpers ---
let get_button_style = |button_focus: AddTableFocus, current_focus| {

View File

@@ -19,20 +19,6 @@ use canvas::{
render_suggestions_dropdown,
DefaultCanvasTheme,
};
use canvas::canvas::HighlightState as CanvasHighlightState;
// Helper function to convert between HighlightState types
fn convert_highlight_state(local: &HighlightState) -> CanvasHighlightState {
match local {
HighlightState::Off => CanvasHighlightState::Off,
HighlightState::Characterwise { anchor } => {
CanvasHighlightState::Characterwise { anchor: *anchor }
}
HighlightState::Linewise { anchor_line } => {
CanvasHighlightState::Linewise { anchor_line: *anchor_line }
}
}
}
pub fn render_login(
f: &mut Frame,
@@ -69,11 +55,8 @@ pub fn render_login(
])
.split(inner_area);
// --- FORM RENDERING (Using new canvas API) ---
let _canvas_highlight_state = convert_highlight_state(highlight_state);
// Wrap LoginState in FormEditor (no clone needed)
let editor = FormEditor::new(login_state);
let editor = FormEditor::new(login_state.clone());
// Use DefaultCanvasTheme instead of app Theme
let input_rect = render_canvas(