logic is being implemented properly well

This commit is contained in:
filipriec
2025-05-25 15:09:38 +02:00
parent 5d0f958a68
commit 85eb3adec7
4 changed files with 238 additions and 251 deletions

View File

@@ -14,7 +14,6 @@ use ratatui::{
use crate::components::handlers::canvas::render_canvas;
use crate::components::common::dialog;
use crate::config::binds::config::EditorKeybindingMode;
use crate::components::common::text_editor::TextEditor;
pub fn render_add_logic(
f: &mut Frame,
@@ -35,7 +34,8 @@ pub fn render_add_logic(
let inner_area = main_block.inner(area);
f.render_widget(main_block, area);
if add_logic_state.current_focus == AddLogicFocus::InputScriptContent {
// Handle full-screen script editing
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
let border_style_color = if is_edit_mode { theme.highlight } else { theme.secondary };
let border_style = Style::default().fg(border_style_color);
@@ -44,18 +44,18 @@ pub fn render_add_logic(
let script_title_hint = match add_logic_state.editor_keybinding_mode {
EditorKeybindingMode::Vim => {
let vim_mode_status = TextEditor::get_vim_mode_status(&add_logic_state.vim_state);
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. Tab navigates from Normal.", vim_mode_status)
format!("Script (VIM {}) - Esc for Normal. Esc again to exit.", vim_mode_status)
} else {
format!("Script (VIM {}) - 'i'/'a'/'o' for Insert. Tab to navigate.", vim_mode_status)
format!("Script (VIM {}) - 'i'/'a'/'o' for Insert. Esc to exit.", vim_mode_status)
}
}
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
if is_edit_mode {
"Script (Editing - Esc to exit edit. Tab navigates after exit.)".to_string()
"Script (Editing - Esc to exit edit. Esc again to exit script.)".to_string()
} else {
"Script (Press Enter or Ctrl+E to edit. Tab to navigate.)".to_string()
"Script (Press Enter or Ctrl+E to edit. Esc to exit.)".to_string()
}
}
};
@@ -68,19 +68,18 @@ pub fn render_add_logic(
.border_type(BorderType::Rounded)
.border_style(border_style),
);
// Remove .widget() call - just pass the reference directly
f.render_widget(&*editor_ref, inner_area);
return;
}
// ... rest of the layout code ...
// Regular layout with preview
let main_chunks = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(3),
Constraint::Length(9),
Constraint::Min(5),
Constraint::Length(3),
Constraint::Length(3), // Top info
Constraint::Length(9), // Canvas
Constraint::Min(5), // Script preview
Constraint::Length(3), // Buttons
])
.split(inner_area);
@@ -89,6 +88,7 @@ pub fn render_add_logic(
let script_content_area = main_chunks[2];
let buttons_area = main_chunks[3];
// Top info
let profile_text = Paragraph::new(vec![
Line::from(Span::styled(
format!("Profile: {}", add_logic_state.profile_name),
@@ -114,6 +114,7 @@ pub fn render_add_logic(
);
f.render_widget(profile_text, top_info_area);
// Canvas
let focus_on_canvas_inputs = matches!(
add_logic_state.current_focus,
AddLogicFocus::InputLogicName
@@ -132,32 +133,41 @@ pub fn render_add_logic(
highlight_state,
);
// Script content preview (like table preview in add_table)
{
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
editor_ref.set_cursor_line_style(Style::default());
let border_style_color = if add_logic_state.current_focus == AddLogicFocus::InputScriptContent {
theme.highlight
let is_script_focused = add_logic_state.current_focus == AddLogicFocus::ScriptContentPreview;
let border_style_color = if is_script_focused {
theme.highlight // Green highlight when focused and ready to select
} else {
theme.secondary
};
let title_hint = match add_logic_state.editor_keybinding_mode {
EditorKeybindingMode::Vim => "Script Preview (VIM - Focus with Tab, then 'i'/'a'/'o' to edit)",
_ => "Script Preview (Focus with Tab, then Enter/Ctrl+E to edit)",
let title_text = if is_script_focused {
"Script Preview (Press Enter to edit) [FOCUSED]"
} else {
"Script Preview"
};
let title_style = if is_script_focused {
Style::default().fg(theme.highlight).add_modifier(Modifier::BOLD)
} else {
Style::default().fg(theme.fg)
};
editor_ref.set_block(
Block::default()
.title(title_hint)
.title(Span::styled(title_text, title_style))
.borders(Borders::ALL)
.border_type(BorderType::Rounded)
.border_style(Style::default().fg(border_style_color)),
);
// Remove .widget() call here too
f.render_widget(&*editor_ref, script_content_area);
}
// 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 {
@@ -222,6 +232,7 @@ pub fn render_add_logic(
);
f.render_widget(cancel_button, button_chunks[1]);
// Dialog
if app_state.ui.dialog.dialog_show {
dialog::render_dialog(
f,