add script now has a proper way of doing things
This commit is contained in:
@@ -14,7 +14,6 @@ use ratatui::{
|
||||
use crate::components::handlers::canvas::render_canvas;
|
||||
use crate::components::common::dialog;
|
||||
use crate::config::binds::config::EditorKeybindingMode;
|
||||
// Remove the CursorStyle import
|
||||
|
||||
pub fn render_add_logic(
|
||||
f: &mut Frame,
|
||||
@@ -22,7 +21,7 @@ pub fn render_add_logic(
|
||||
theme: &Theme,
|
||||
app_state: &AppState,
|
||||
add_logic_state: &mut AddLogicState,
|
||||
is_edit_mode: bool,
|
||||
is_edit_mode: bool, // Used for border/title hints in InsideScriptContent
|
||||
highlight_state: &HighlightState,
|
||||
) {
|
||||
let main_block = Block::default()
|
||||
@@ -42,31 +41,23 @@ pub fn render_add_logic(
|
||||
let border_style = Style::default().fg(border_style_color);
|
||||
|
||||
editor_ref.set_cursor_line_style(Style::default());
|
||||
|
||||
// Set cursor style: underscore when not in edit mode, block when in edit mode
|
||||
let cursor_style = if is_edit_mode {
|
||||
// Block cursor (default reversed style)
|
||||
Style::default().bg(theme.highlight).fg(theme.bg)
|
||||
} else {
|
||||
// Underscore cursor (underline style)
|
||||
Style::default().add_modifier(Modifier::UNDERLINED).fg(theme.highlight)
|
||||
};
|
||||
editor_ref.set_cursor_style(cursor_style);
|
||||
// Explicitly set to tui-textarea's default "active" editing cursor style
|
||||
editor_ref.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
|
||||
let script_title_hint = match add_logic_state.editor_keybinding_mode {
|
||||
EditorKeybindingMode::Vim => {
|
||||
let vim_mode_status = crate::components::common::text_editor::TextEditor::get_vim_mode_status(&add_logic_state.vim_state);
|
||||
if is_edit_mode {
|
||||
format!("Script (VIM {}) - Esc for Normal. Esc again to exit.", vim_mode_status)
|
||||
if is_edit_mode { // is_edit_mode here refers to Vim's Insert mode
|
||||
format!("Script {}", vim_mode_status)
|
||||
} else {
|
||||
format!("Script (VIM {}) - 'i'/'a'/'o' for Insert. Esc to exit.", vim_mode_status)
|
||||
format!("Script {}", vim_mode_status)
|
||||
}
|
||||
}
|
||||
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
|
||||
if is_edit_mode {
|
||||
"Script (Editing - Esc to exit edit. Esc again to exit script.)".to_string()
|
||||
"Script (Editing)".to_string()
|
||||
} else {
|
||||
"Script (Press Enter or Ctrl+E to edit. Esc to exit.)".to_string()
|
||||
"Script".to_string()
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -140,35 +131,41 @@ pub fn render_add_logic(
|
||||
&add_logic_state.current_field(),
|
||||
&add_logic_state.inputs(),
|
||||
theme,
|
||||
is_edit_mode && focus_on_canvas_inputs,
|
||||
is_edit_mode && focus_on_canvas_inputs, // is_edit_mode for canvas fields
|
||||
highlight_state,
|
||||
);
|
||||
|
||||
// Script content preview (like table preview in add_table)
|
||||
// Script content preview
|
||||
{
|
||||
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
|
||||
editor_ref.set_cursor_line_style(Style::default());
|
||||
|
||||
// Set cursor style for preview mode (underscore style)
|
||||
let preview_cursor_style = Style::default()
|
||||
let is_script_preview_focused = add_logic_state.current_focus == AddLogicFocus::ScriptContentPreview;
|
||||
|
||||
if is_script_preview_focused {
|
||||
// When script PREVIEW is focused, use tui-textarea's default "active" cursor (block-like).
|
||||
editor_ref.set_cursor_style(Style::default().add_modifier(Modifier::REVERSED));
|
||||
} else {
|
||||
// When script PREVIEW is NOT focused, use an underscore cursor.
|
||||
let underscore_cursor_style = Style::default()
|
||||
.add_modifier(Modifier::UNDERLINED)
|
||||
.fg(theme.secondary);
|
||||
editor_ref.set_cursor_style(preview_cursor_style);
|
||||
editor_ref.set_cursor_style(underscore_cursor_style);
|
||||
}
|
||||
|
||||
let is_script_focused = add_logic_state.current_focus == AddLogicFocus::ScriptContentPreview;
|
||||
let border_style_color = if is_script_focused {
|
||||
let border_style_color = if is_script_preview_focused {
|
||||
theme.highlight // Green highlight when focused and ready to select
|
||||
} else {
|
||||
theme.secondary
|
||||
};
|
||||
|
||||
let title_text = if is_script_focused {
|
||||
"Script Preview (Press Enter to edit) [FOCUSED]"
|
||||
let title_text = if is_script_preview_focused {
|
||||
"Script Preview"
|
||||
} else {
|
||||
"Script Preview"
|
||||
};
|
||||
|
||||
let title_style = if is_script_focused {
|
||||
let title_style = if is_script_preview_focused {
|
||||
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
|
||||
} else {
|
||||
Style::default().fg(theme.fg)
|
||||
@@ -184,7 +181,7 @@ pub fn render_add_logic(
|
||||
f.render_widget(&*editor_ref, script_content_area);
|
||||
}
|
||||
|
||||
// Buttons (rest remains the same)
|
||||
// Buttons
|
||||
let get_button_style = |button_focus: AddLogicFocus, current_focus| {
|
||||
let is_focused = current_focus == button_focus;
|
||||
let base_style = Style::default().fg(if is_focused {
|
||||
|
||||
Reference in New Issue
Block a user