text area working now perfectly well
This commit is contained in:
@@ -1,5 +1,10 @@
|
||||
// src/state/pages/add_logic.rs
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use std::cell::RefCell;
|
||||
use std::rc::Rc;
|
||||
use tui_textarea::TextArea;
|
||||
// Removed unused Style, Color imports if not used in Default for TextArea styling
|
||||
// use ratatui::style::{Color, Style}; // Keep if you add custom styling in default()
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
pub enum AddLogicFocus {
|
||||
@@ -12,46 +17,47 @@ pub enum AddLogicFocus {
|
||||
CancelButton,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct AddLogicState {
|
||||
pub profile_name: String,
|
||||
pub selected_table_id: Option<i64>,
|
||||
pub selected_table_name: Option<String>,
|
||||
pub logic_name_input: String,
|
||||
pub target_column_input: String,
|
||||
pub script_content_input: String,
|
||||
pub script_content_editor: Rc<RefCell<TextArea<'static>>>,
|
||||
pub description_input: String,
|
||||
pub current_focus: AddLogicFocus,
|
||||
pub logic_name_cursor_pos: usize,
|
||||
pub target_column_cursor_pos: usize,
|
||||
pub script_content_scroll: (u16, u16), // (vertical, horizontal)
|
||||
pub description_cursor_pos: usize,
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
impl Default for AddLogicState {
|
||||
fn default() -> Self {
|
||||
let editor = TextArea::default(); // No 'mut' needed if not modified further here
|
||||
// Example: editor.set_placeholder_text("Enter script...");
|
||||
// Example: editor.set_line_number_style(Style::default().fg(Color::DarkGray));
|
||||
AddLogicState {
|
||||
profile_name: "default".to_string(),
|
||||
selected_table_id: None,
|
||||
selected_table_name: None,
|
||||
logic_name_input: String::new(),
|
||||
target_column_input: String::new(),
|
||||
script_content_input: String::new(),
|
||||
script_content_editor: Rc::new(RefCell::new(editor)),
|
||||
description_input: String::new(),
|
||||
current_focus: AddLogicFocus::InputLogicName,
|
||||
logic_name_cursor_pos: 0,
|
||||
target_column_cursor_pos: 0,
|
||||
script_content_scroll: (0, 0),
|
||||
description_cursor_pos: 0,
|
||||
has_unsaved_changes: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ... rest of the CanvasState impl remains the same
|
||||
impl AddLogicState {
|
||||
// Number of canvas-editable fields
|
||||
pub const INPUT_FIELD_COUNT: usize = 3; // Logic Name, Target Column, Description
|
||||
pub const INPUT_FIELD_COUNT: usize = 3;
|
||||
}
|
||||
|
||||
impl CanvasState for AddLogicState {
|
||||
@@ -60,7 +66,7 @@ impl CanvasState for AddLogicState {
|
||||
AddLogicFocus::InputLogicName => 0,
|
||||
AddLogicFocus::InputTargetColumn => 1,
|
||||
AddLogicFocus::InputDescription => 2,
|
||||
_ => 0, // Default or non-input focus
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +105,7 @@ impl CanvasState for AddLogicState {
|
||||
AddLogicFocus::InputLogicName => &mut self.logic_name_input,
|
||||
AddLogicFocus::InputTargetColumn => &mut self.target_column_input,
|
||||
AddLogicFocus::InputDescription => &mut self.description_input,
|
||||
_ => &mut self.logic_name_input, // Placeholder, should not be hit if focus is correct
|
||||
_ => &mut self.logic_name_input,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -112,7 +118,7 @@ impl CanvasState for AddLogicState {
|
||||
0 => AddLogicFocus::InputLogicName,
|
||||
1 => AddLogicFocus::InputTargetColumn,
|
||||
2 => AddLogicFocus::InputDescription,
|
||||
_ => self.current_focus, // Stay if out of bounds
|
||||
_ => self.current_focus,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -122,10 +128,12 @@ impl CanvasState for AddLogicState {
|
||||
self.logic_name_cursor_pos = pos.min(self.logic_name_input.len());
|
||||
}
|
||||
AddLogicFocus::InputTargetColumn => {
|
||||
self.target_column_cursor_pos = pos.min(self.target_column_input.len());
|
||||
self.target_column_cursor_pos =
|
||||
pos.min(self.target_column_input.len());
|
||||
}
|
||||
AddLogicFocus::InputDescription => {
|
||||
self.description_cursor_pos = pos.min(self.description_input.len());
|
||||
self.description_cursor_pos =
|
||||
pos.min(self.description_input.len());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user