fixing is_edit_mode flag removal
This commit is contained in:
@@ -46,7 +46,6 @@ pub fn render_bottom_panel(
|
|||||||
chunk_idx: &mut usize,
|
chunk_idx: &mut usize,
|
||||||
current_dir: &str,
|
current_dir: &str,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_event_handler_edit_mode: bool,
|
|
||||||
current_fps: f64,
|
current_fps: f64,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
navigation_state: &NavigationState,
|
navigation_state: &NavigationState,
|
||||||
@@ -74,7 +73,6 @@ pub fn render_bottom_panel(
|
|||||||
status_line_area,
|
status_line_area,
|
||||||
current_dir,
|
current_dir,
|
||||||
theme,
|
theme,
|
||||||
is_event_handler_edit_mode,
|
|
||||||
current_fps,
|
current_fps,
|
||||||
app_state,
|
app_state,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ pub fn render_add_logic(
|
|||||||
// Handle full-screen script editing
|
// Handle full-screen script editing
|
||||||
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||||
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_ref = add_logic_state.script_content_editor.borrow_mut();
|
||||||
let border_style_color = if editor.mode() == canvas::AppMode::Edit {
|
let border_style_color = if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(&add_logic_state.vim_state) {
|
||||||
theme.highlight
|
theme.highlight
|
||||||
} else {
|
} else {
|
||||||
theme.secondary
|
theme.secondary
|
||||||
@@ -50,7 +50,7 @@ pub fn render_add_logic(
|
|||||||
format!("Script {}", vim_mode_status)
|
format!("Script {}", vim_mode_status)
|
||||||
}
|
}
|
||||||
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
|
EditorKeybindingMode::Emacs | EditorKeybindingMode::Default => {
|
||||||
if editor.mode() == canvas::AppMode::Edit {
|
if crate::components::common::text_editor::TextEditor::is_vim_insert_mode(&add_logic_state.vim_state) {
|
||||||
"Script (Editing)".to_string()
|
"Script (Editing)".to_string()
|
||||||
} else {
|
} else {
|
||||||
"Script".to_string()
|
"Script".to_string()
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ pub fn render_add_table(
|
|||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
add_table_state: &mut AddTableState,
|
add_table_state: &mut AddTableState,
|
||||||
is_edit_mode: bool, // Determines if canvas inputs are in edit mode
|
|
||||||
) {
|
) {
|
||||||
// --- Configuration ---
|
// --- Configuration ---
|
||||||
// Threshold width to switch between wide and narrow layouts
|
// Threshold width to switch between wide and narrow layouts
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// src/functions/modes/navigation/add_logic_nav.rs
|
// src/functions/modes/navigation/add_logic_nav.rs
|
||||||
|
|
||||||
use crate::config::binds::config::{Config, EditorKeybindingMode};
|
use crate::config::binds::config::{Config, EditorKeybindingMode};
|
||||||
use crate::state::{
|
use crate::state::{
|
||||||
app::state::AppState,
|
app::state::AppState,
|
||||||
@@ -21,7 +22,6 @@ pub fn handle_add_logic_navigation(
|
|||||||
key_event: KeyEvent,
|
key_event: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
is_edit_mode: &mut bool,
|
|
||||||
buffer_state: &mut BufferState,
|
buffer_state: &mut BufferState,
|
||||||
grpc_client: GrpcClient,
|
grpc_client: GrpcClient,
|
||||||
save_logic_sender: SaveLogicResultSender,
|
save_logic_sender: SaveLogicResultSender,
|
||||||
@@ -29,18 +29,17 @@ pub fn handle_add_logic_navigation(
|
|||||||
router: &mut Router,
|
router: &mut Router,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
if let Page::AddLogic(add_logic_state) = &mut router.current {
|
if let Page::AddLogic(add_logic_state) = &mut router.current {
|
||||||
|
// === FULLSCREEN SCRIPT EDITING ===
|
||||||
// === FULLSCREEN SCRIPT EDITING - COMPLETE ISOLATION ===
|
|
||||||
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||||
// === AUTOCOMPLETE HANDLING ===
|
// === AUTOCOMPLETE HANDLING ===
|
||||||
if add_logic_state.script_editor_autocomplete_active {
|
if add_logic_state.script_editor_autocomplete_active {
|
||||||
match key_event.code {
|
match key_event.code {
|
||||||
// ... (Char, Backspace, Tab, Down, Up cases remain the same) ...
|
|
||||||
KeyCode::Char(c) if c.is_alphanumeric() || c == '_' => {
|
KeyCode::Char(c) if c.is_alphanumeric() || c == '_' => {
|
||||||
add_logic_state.script_editor_filter_text.push(c);
|
add_logic_state.script_editor_filter_text.push(c);
|
||||||
add_logic_state.update_script_editor_suggestions();
|
add_logic_state.update_script_editor_suggestions();
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -48,7 +47,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
&mut add_logic_state.vim_state,
|
&mut add_logic_state.vim_state,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
*command_message = format!("Filtering: @{}", add_logic_state.script_editor_filter_text);
|
*command_message =
|
||||||
|
format!("Filtering: @{}", add_logic_state.script_editor_filter_text);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
KeyCode::Backspace => {
|
KeyCode::Backspace => {
|
||||||
@@ -56,7 +56,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
add_logic_state.script_editor_filter_text.pop();
|
add_logic_state.script_editor_filter_text.pop();
|
||||||
add_logic_state.update_script_editor_suggestions();
|
add_logic_state.update_script_editor_suggestions();
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -64,18 +65,27 @@ pub fn handle_add_logic_navigation(
|
|||||||
&mut add_logic_state.vim_state,
|
&mut add_logic_state.vim_state,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
*command_message = if add_logic_state.script_editor_filter_text.is_empty() {
|
*command_message =
|
||||||
|
if add_logic_state.script_editor_filter_text.is_empty() {
|
||||||
"Autocomplete: @".to_string()
|
"Autocomplete: @".to_string()
|
||||||
} else {
|
} else {
|
||||||
format!("Filtering: @{}", add_logic_state.script_editor_filter_text)
|
format!(
|
||||||
|
"Filtering: @{}",
|
||||||
|
add_logic_state.script_editor_filter_text
|
||||||
|
)
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
let should_deactivate = if let Some((trigger_line, trigger_col)) = add_logic_state.script_editor_trigger_position {
|
let should_deactivate =
|
||||||
|
if let Some((trigger_line, trigger_col)) =
|
||||||
|
add_logic_state.script_editor_trigger_position
|
||||||
|
{
|
||||||
let current_cursor = {
|
let current_cursor = {
|
||||||
let editor_borrow = add_logic_state.script_content_editor.borrow();
|
let editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow();
|
||||||
editor_borrow.cursor()
|
editor_borrow.cursor()
|
||||||
};
|
};
|
||||||
current_cursor.0 == trigger_line && current_cursor.1 == trigger_col + 1
|
current_cursor.0 == trigger_line
|
||||||
|
&& current_cursor.1 == trigger_col + 1
|
||||||
} else {
|
} else {
|
||||||
false
|
false
|
||||||
};
|
};
|
||||||
@@ -84,7 +94,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
*command_message = "Autocomplete cancelled".to_string();
|
*command_message = "Autocomplete cancelled".to_string();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -97,75 +108,120 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
KeyCode::Tab | KeyCode::Down => {
|
KeyCode::Tab | KeyCode::Down => {
|
||||||
if !add_logic_state.script_editor_suggestions.is_empty() {
|
if !add_logic_state.script_editor_suggestions.is_empty() {
|
||||||
let current = add_logic_state.script_editor_selected_suggestion_index.unwrap_or(0);
|
let current = add_logic_state
|
||||||
let next = (current + 1) % add_logic_state.script_editor_suggestions.len();
|
.script_editor_selected_suggestion_index
|
||||||
|
.unwrap_or(0);
|
||||||
|
let next =
|
||||||
|
(current + 1) % add_logic_state.script_editor_suggestions.len();
|
||||||
add_logic_state.script_editor_selected_suggestion_index = Some(next);
|
add_logic_state.script_editor_selected_suggestion_index = Some(next);
|
||||||
*command_message = format!("Selected: {}", add_logic_state.script_editor_suggestions[next]);
|
*command_message = format!(
|
||||||
|
"Selected: {}",
|
||||||
|
add_logic_state.script_editor_suggestions[next]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
KeyCode::Up => {
|
KeyCode::Up => {
|
||||||
if !add_logic_state.script_editor_suggestions.is_empty() {
|
if !add_logic_state.script_editor_suggestions.is_empty() {
|
||||||
let current = add_logic_state.script_editor_selected_suggestion_index.unwrap_or(0);
|
let current = add_logic_state
|
||||||
|
.script_editor_selected_suggestion_index
|
||||||
|
.unwrap_or(0);
|
||||||
let prev = if current == 0 {
|
let prev = if current == 0 {
|
||||||
add_logic_state.script_editor_suggestions.len() - 1
|
add_logic_state.script_editor_suggestions.len() - 1
|
||||||
} else {
|
} else {
|
||||||
current - 1
|
current - 1
|
||||||
};
|
};
|
||||||
add_logic_state.script_editor_selected_suggestion_index = Some(prev);
|
add_logic_state.script_editor_selected_suggestion_index = Some(prev);
|
||||||
*command_message = format!("Selected: {}", add_logic_state.script_editor_suggestions[prev]);
|
*command_message = format!(
|
||||||
|
"Selected: {}",
|
||||||
|
add_logic_state.script_editor_suggestions[prev]
|
||||||
|
);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
KeyCode::Enter => {
|
KeyCode::Enter => {
|
||||||
if let Some(selected_idx) = add_logic_state.script_editor_selected_suggestion_index {
|
if let Some(selected_idx) =
|
||||||
if let Some(suggestion) = add_logic_state.script_editor_suggestions.get(selected_idx).cloned() {
|
add_logic_state.script_editor_selected_suggestion_index
|
||||||
let trigger_pos = add_logic_state.script_editor_trigger_position;
|
{
|
||||||
let filter_len = add_logic_state.script_editor_filter_text.len();
|
if let Some(suggestion) = add_logic_state
|
||||||
|
.script_editor_suggestions
|
||||||
|
.get(selected_idx)
|
||||||
|
.cloned()
|
||||||
|
{
|
||||||
|
let trigger_pos =
|
||||||
|
add_logic_state.script_editor_trigger_position;
|
||||||
|
let filter_len =
|
||||||
|
add_logic_state.script_editor_filter_text.len();
|
||||||
|
|
||||||
add_logic_state.deactivate_script_editor_autocomplete();
|
add_logic_state.deactivate_script_editor_autocomplete();
|
||||||
add_logic_state.has_unsaved_changes = true;
|
add_logic_state.has_unsaved_changes = true;
|
||||||
|
|
||||||
if let Some(pos) = trigger_pos {
|
if let Some(pos) = trigger_pos {
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
|
|
||||||
if suggestion == "sql" {
|
if suggestion == "sql" {
|
||||||
replace_autocomplete_text(&mut editor_borrow, pos, filter_len, "sql");
|
replace_autocomplete_text(
|
||||||
|
&mut editor_borrow,
|
||||||
|
pos,
|
||||||
|
filter_len,
|
||||||
|
"sql",
|
||||||
|
);
|
||||||
editor_borrow.insert_str("('')");
|
editor_borrow.insert_str("('')");
|
||||||
// Move cursor back twice to be between the single quotes
|
editor_borrow.move_cursor(CursorMove::Back);
|
||||||
editor_borrow.move_cursor(CursorMove::Back); // Before ')'
|
editor_borrow.move_cursor(CursorMove::Back);
|
||||||
editor_borrow.move_cursor(CursorMove::Back); // Before ''' (inside '')
|
|
||||||
*command_message = "Inserted: @sql('')".to_string();
|
*command_message = "Inserted: @sql('')".to_string();
|
||||||
} else {
|
} else {
|
||||||
let is_table_selection = add_logic_state.is_table_name_suggestion(&suggestion);
|
let is_table_selection =
|
||||||
replace_autocomplete_text(&mut editor_borrow, pos, filter_len, &suggestion);
|
add_logic_state.is_table_name_suggestion(&suggestion);
|
||||||
|
replace_autocomplete_text(
|
||||||
|
&mut editor_borrow,
|
||||||
|
pos,
|
||||||
|
filter_len,
|
||||||
|
&suggestion,
|
||||||
|
);
|
||||||
|
|
||||||
if is_table_selection {
|
if is_table_selection {
|
||||||
editor_borrow.insert_str(".");
|
editor_borrow.insert_str(".");
|
||||||
let new_cursor = editor_borrow.cursor();
|
let new_cursor = editor_borrow.cursor();
|
||||||
drop(editor_borrow); // Release borrow before calling add_logic_state methods
|
drop(editor_borrow);
|
||||||
|
|
||||||
add_logic_state.script_editor_trigger_position = Some(new_cursor);
|
add_logic_state.script_editor_trigger_position =
|
||||||
|
Some(new_cursor);
|
||||||
add_logic_state.script_editor_autocomplete_active = true;
|
add_logic_state.script_editor_autocomplete_active = true;
|
||||||
add_logic_state.script_editor_filter_text.clear();
|
add_logic_state.script_editor_filter_text.clear();
|
||||||
add_logic_state.trigger_column_autocomplete_for_table(suggestion.clone());
|
add_logic_state
|
||||||
|
.trigger_column_autocomplete_for_table(
|
||||||
|
suggestion.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
let profile_name = add_logic_state.profile_name.clone();
|
let profile_name =
|
||||||
|
add_logic_state.profile_name.clone();
|
||||||
let table_name_for_fetch = suggestion.clone();
|
let table_name_for_fetch = suggestion.clone();
|
||||||
let mut client_clone = grpc_client.clone();
|
let mut client_clone = grpc_client.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
match UiService::fetch_columns_for_table(&mut client_clone, &profile_name, &table_name_for_fetch).await {
|
if let Err(e) = UiService::fetch_columns_for_table(
|
||||||
Ok(_columns) => {
|
&mut client_clone,
|
||||||
// Result handled by main UI loop
|
&profile_name,
|
||||||
}
|
&table_name_for_fetch,
|
||||||
Err(e) => {
|
)
|
||||||
tracing::error!("Failed to fetch columns for {}.{}: {}", profile_name, table_name_for_fetch, e);
|
.await
|
||||||
}
|
{
|
||||||
|
tracing::error!(
|
||||||
|
"Failed to fetch columns for {}.{}: {}",
|
||||||
|
profile_name,
|
||||||
|
table_name_for_fetch,
|
||||||
|
e
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
*command_message = format!("Selected table '{}', fetching columns...", suggestion);
|
*command_message = format!(
|
||||||
|
"Selected table '{}', fetching columns...",
|
||||||
|
suggestion
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
*command_message = format!("Inserted: {}", suggestion);
|
*command_message =
|
||||||
|
format!("Inserted: {}", suggestion);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +230,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
add_logic_state.deactivate_script_editor_autocomplete();
|
add_logic_state.deactivate_script_editor_autocomplete();
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -192,7 +249,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
add_logic_state.deactivate_script_editor_autocomplete();
|
add_logic_state.deactivate_script_editor_autocomplete();
|
||||||
*command_message = "Autocomplete cancelled".to_string();
|
*command_message = "Autocomplete cancelled".to_string();
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -205,9 +263,12 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger autocomplete with '@'
|
||||||
if key_event.code == KeyCode::Char('@') && key_event.modifiers == KeyModifiers::NONE {
|
if key_event.code == KeyCode::Char('@') && key_event.modifiers == KeyModifiers::NONE {
|
||||||
let should_trigger = match add_logic_state.editor_keybinding_mode {
|
let should_trigger = match add_logic_state.editor_keybinding_mode {
|
||||||
EditorKeybindingMode::Vim => *is_edit_mode,
|
EditorKeybindingMode::Vim => {
|
||||||
|
TextEditor::is_vim_insert_mode(&add_logic_state.vim_state)
|
||||||
|
}
|
||||||
_ => true,
|
_ => true,
|
||||||
};
|
};
|
||||||
if should_trigger {
|
if should_trigger {
|
||||||
@@ -216,7 +277,8 @@ pub fn handle_add_logic_navigation(
|
|||||||
editor_borrow.cursor()
|
editor_borrow.cursor()
|
||||||
};
|
};
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -234,12 +296,15 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Esc handling
|
||||||
if key_event.code == KeyCode::Esc && key_event.modifiers == KeyModifiers::NONE {
|
if key_event.code == KeyCode::Esc && key_event.modifiers == KeyModifiers::NONE {
|
||||||
match add_logic_state.editor_keybinding_mode {
|
match add_logic_state.editor_keybinding_mode {
|
||||||
EditorKeybindingMode::Vim => {
|
EditorKeybindingMode::Vim => {
|
||||||
if *is_edit_mode {
|
let was_insert =
|
||||||
|
TextEditor::is_vim_insert_mode(&add_logic_state.vim_state);
|
||||||
{
|
{
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow =
|
||||||
|
add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
&mut editor_borrow,
|
&mut editor_borrow,
|
||||||
key_event,
|
key_event,
|
||||||
@@ -247,32 +312,26 @@ pub fn handle_add_logic_navigation(
|
|||||||
&mut add_logic_state.vim_state,
|
&mut add_logic_state.vim_state,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if TextEditor::is_vim_normal_mode(&add_logic_state.vim_state) {
|
if was_insert {
|
||||||
*is_edit_mode = false;
|
*command_message =
|
||||||
*command_message = "VIM: Normal Mode. Esc again to exit script.".to_string();
|
"VIM: Normal Mode. Esc again to exit script.".to_string();
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
add_logic_state.current_focus = AddLogicFocus::ScriptContentPreview;
|
add_logic_state.current_focus =
|
||||||
|
AddLogicFocus::ScriptContentPreview;
|
||||||
app_state.ui.focus_outside_canvas = true;
|
app_state.ui.focus_outside_canvas = true;
|
||||||
*is_edit_mode = false;
|
|
||||||
*command_message = "Exited script editing.".to_string();
|
*command_message = "Exited script editing.".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
if *is_edit_mode {
|
|
||||||
*is_edit_mode = false;
|
|
||||||
*command_message = "Exited script edit. Esc again to exit script.".to_string();
|
|
||||||
} else {
|
|
||||||
add_logic_state.current_focus = AddLogicFocus::ScriptContentPreview;
|
add_logic_state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||||
app_state.ui.focus_outside_canvas = true;
|
app_state.ui.focus_outside_canvas = true;
|
||||||
*is_edit_mode = false;
|
|
||||||
*command_message = "Exited script editing.".to_string();
|
*command_message = "Exited script editing.".to_string();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normal text input
|
||||||
let changed = {
|
let changed = {
|
||||||
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
let mut editor_borrow = add_logic_state.script_content_editor.borrow_mut();
|
||||||
TextEditor::handle_input(
|
TextEditor::handle_input(
|
||||||
@@ -285,12 +344,10 @@ pub fn handle_add_logic_navigation(
|
|||||||
if changed {
|
if changed {
|
||||||
add_logic_state.has_unsaved_changes = true;
|
add_logic_state.has_unsaved_changes = true;
|
||||||
}
|
}
|
||||||
if add_logic_state.editor_keybinding_mode == EditorKeybindingMode::Vim {
|
|
||||||
*is_edit_mode = !TextEditor::is_vim_normal_mode(&add_logic_state.vim_state);
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// === NON-FULLSCREEN NAVIGATION ===
|
||||||
let action = config.get_general_action(key_event.code, key_event.modifiers);
|
let action = config.get_general_action(key_event.code, key_event.modifiers);
|
||||||
let current_focus = add_logic_state.current_focus;
|
let current_focus = add_logic_state.current_focus;
|
||||||
let mut handled = true;
|
let mut handled = true;
|
||||||
@@ -304,8 +361,12 @@ pub fn handle_add_logic_navigation(
|
|||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::InputLogicName => {}
|
AddLogicFocus::InputLogicName => {}
|
||||||
AddLogicFocus::InputTargetColumn => new_focus = AddLogicFocus::InputLogicName,
|
AddLogicFocus::InputTargetColumn => new_focus = AddLogicFocus::InputLogicName,
|
||||||
AddLogicFocus::InputDescription => new_focus = AddLogicFocus::InputTargetColumn,
|
AddLogicFocus::InputDescription => {
|
||||||
AddLogicFocus::ScriptContentPreview => new_focus = AddLogicFocus::InputDescription,
|
new_focus = AddLogicFocus::InputTargetColumn
|
||||||
|
}
|
||||||
|
AddLogicFocus::ScriptContentPreview => {
|
||||||
|
new_focus = AddLogicFocus::InputDescription
|
||||||
|
}
|
||||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::ScriptContentPreview,
|
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::ScriptContentPreview,
|
||||||
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
||||||
_ => handled = false,
|
_ => handled = false,
|
||||||
@@ -313,13 +374,19 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
Some("move_down") => {
|
Some("move_down") => {
|
||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::InputLogicName => new_focus = AddLogicFocus::InputTargetColumn,
|
AddLogicFocus::InputLogicName => {
|
||||||
AddLogicFocus::InputTargetColumn => new_focus = AddLogicFocus::InputDescription,
|
new_focus = AddLogicFocus::InputTargetColumn
|
||||||
|
}
|
||||||
|
AddLogicFocus::InputTargetColumn => {
|
||||||
|
new_focus = AddLogicFocus::InputDescription
|
||||||
|
}
|
||||||
AddLogicFocus::InputDescription => {
|
AddLogicFocus::InputDescription => {
|
||||||
add_logic_state.last_canvas_field = 2;
|
add_logic_state.last_canvas_field = 2;
|
||||||
new_focus = AddLogicFocus::ScriptContentPreview;
|
new_focus = AddLogicFocus::ScriptContentPreview;
|
||||||
},
|
}
|
||||||
AddLogicFocus::ScriptContentPreview => new_focus = AddLogicFocus::SaveButton,
|
AddLogicFocus::ScriptContentPreview => {
|
||||||
|
new_focus = AddLogicFocus::SaveButton
|
||||||
|
}
|
||||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
||||||
AddLogicFocus::CancelButton => {}
|
AddLogicFocus::CancelButton => {}
|
||||||
_ => handled = false,
|
_ => handled = false,
|
||||||
@@ -327,9 +394,14 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
Some("next_option") => {
|
Some("next_option") => {
|
||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription =>
|
AddLogicFocus::InputLogicName
|
||||||
{ new_focus = AddLogicFocus::ScriptContentPreview; }
|
| AddLogicFocus::InputTargetColumn
|
||||||
AddLogicFocus::ScriptContentPreview => new_focus = AddLogicFocus::SaveButton,
|
| AddLogicFocus::InputDescription => {
|
||||||
|
new_focus = AddLogicFocus::ScriptContentPreview
|
||||||
|
}
|
||||||
|
AddLogicFocus::ScriptContentPreview => {
|
||||||
|
new_focus = AddLogicFocus::SaveButton
|
||||||
|
}
|
||||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::CancelButton,
|
||||||
AddLogicFocus::CancelButton => {}
|
AddLogicFocus::CancelButton => {}
|
||||||
_ => handled = false,
|
_ => handled = false,
|
||||||
@@ -337,10 +409,15 @@ pub fn handle_add_logic_navigation(
|
|||||||
}
|
}
|
||||||
Some("previous_option") => {
|
Some("previous_option") => {
|
||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription =>
|
AddLogicFocus::InputLogicName
|
||||||
{ }
|
| AddLogicFocus::InputTargetColumn
|
||||||
AddLogicFocus::ScriptContentPreview => new_focus = AddLogicFocus::InputDescription,
|
| AddLogicFocus::InputDescription => {}
|
||||||
AddLogicFocus::SaveButton => new_focus = AddLogicFocus::ScriptContentPreview,
|
AddLogicFocus::ScriptContentPreview => {
|
||||||
|
new_focus = AddLogicFocus::InputDescription
|
||||||
|
}
|
||||||
|
AddLogicFocus::SaveButton => {
|
||||||
|
new_focus = AddLogicFocus::ScriptContentPreview
|
||||||
|
}
|
||||||
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
AddLogicFocus::CancelButton => new_focus = AddLogicFocus::SaveButton,
|
||||||
_ => handled = false,
|
_ => handled = false,
|
||||||
}
|
}
|
||||||
@@ -371,35 +448,47 @@ pub fn handle_add_logic_navigation(
|
|||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::ScriptContentPreview => {
|
AddLogicFocus::ScriptContentPreview => {
|
||||||
new_focus = AddLogicFocus::InsideScriptContent;
|
new_focus = AddLogicFocus::InsideScriptContent;
|
||||||
*is_edit_mode = false;
|
|
||||||
app_state.ui.focus_outside_canvas = false;
|
app_state.ui.focus_outside_canvas = false;
|
||||||
let mode_hint = match add_logic_state.editor_keybinding_mode {
|
let mode_hint = match add_logic_state.editor_keybinding_mode {
|
||||||
EditorKeybindingMode::Vim => "VIM mode - 'i'/'a'/'o' to edit",
|
EditorKeybindingMode::Vim => {
|
||||||
|
"VIM mode - 'i'/'a'/'o' to edit"
|
||||||
|
}
|
||||||
_ => "Enter/Ctrl+E to edit",
|
_ => "Enter/Ctrl+E to edit",
|
||||||
};
|
};
|
||||||
*command_message = format!("Fullscreen script editing. {} or Esc to exit.", mode_hint);
|
*command_message = format!(
|
||||||
|
"Fullscreen script editing. {} or Esc to exit.",
|
||||||
|
mode_hint
|
||||||
|
);
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
AddLogicFocus::SaveButton => {
|
AddLogicFocus::SaveButton => {
|
||||||
*command_message = "Save logic action".to_string();
|
*command_message = "Save logic action".to_string();
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
AddLogicFocus::CancelButton => {
|
AddLogicFocus::CancelButton => {
|
||||||
buffer_state.update_history(AppView::Admin);
|
buffer_state.update_history(AppView::Admin);
|
||||||
*command_message = "Cancelled Add Logic".to_string();
|
*command_message = "Cancelled Add Logic".to_string();
|
||||||
*is_edit_mode = false;
|
handled = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription => {
|
AddLogicFocus::InputLogicName
|
||||||
*is_edit_mode = !*is_edit_mode;
|
| AddLogicFocus::InputTargetColumn
|
||||||
*command_message = format!("Field edit mode: {}", if *is_edit_mode { "ON" } else { "OFF" });
|
| AddLogicFocus::InputDescription => {
|
||||||
|
// Focus canvas inputs; let canvas keymap handle editing
|
||||||
|
app_state.ui.focus_outside_canvas = false;
|
||||||
|
handled = false; // forward to canvas
|
||||||
}
|
}
|
||||||
_ => handled = false,
|
_ => handled = false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some("toggle_edit_mode") => {
|
Some("toggle_edit_mode") => {
|
||||||
match current_focus {
|
match current_focus {
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription => {
|
AddLogicFocus::InputLogicName
|
||||||
*is_edit_mode = !*is_edit_mode;
|
| AddLogicFocus::InputTargetColumn
|
||||||
*command_message = format!("Canvas field edit mode: {}", if *is_edit_mode { "ON" } else { "OFF" });
|
| AddLogicFocus::InputDescription => {
|
||||||
|
app_state.ui.focus_outside_canvas = false;
|
||||||
|
*command_message =
|
||||||
|
"Focus moved to input. Use i/a (Vim) or type to edit.".to_string();
|
||||||
|
handled = true;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
*command_message = "Cannot toggle edit mode here.".to_string();
|
*command_message = "Cannot toggle edit mode here.".to_string();
|
||||||
@@ -411,22 +500,21 @@ pub fn handle_add_logic_navigation(
|
|||||||
|
|
||||||
if handled && current_focus != new_focus {
|
if handled && current_focus != new_focus {
|
||||||
add_logic_state.current_focus = new_focus;
|
add_logic_state.current_focus = new_focus;
|
||||||
let new_is_canvas_input_focus = matches!(new_focus,
|
let new_is_canvas_input_focus = matches!(
|
||||||
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription
|
new_focus,
|
||||||
|
AddLogicFocus::InputLogicName
|
||||||
|
| AddLogicFocus::InputTargetColumn
|
||||||
|
| AddLogicFocus::InputDescription
|
||||||
);
|
);
|
||||||
if new_is_canvas_input_focus {
|
if new_is_canvas_input_focus {
|
||||||
*is_edit_mode = false;
|
|
||||||
app_state.ui.focus_outside_canvas = false;
|
app_state.ui.focus_outside_canvas = false;
|
||||||
} else {
|
} else {
|
||||||
app_state.ui.focus_outside_canvas = true;
|
app_state.ui.focus_outside_canvas = true;
|
||||||
if matches!(new_focus, AddLogicFocus::ScriptContentPreview) {
|
|
||||||
*is_edit_mode = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
handled
|
handled
|
||||||
} else {
|
} else {
|
||||||
return false; // not on AddLogic page
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,7 +524,6 @@ fn replace_autocomplete_text(
|
|||||||
filter_len: usize,
|
filter_len: usize,
|
||||||
replacement: &str,
|
replacement: &str,
|
||||||
) {
|
) {
|
||||||
// use tui_textarea::CursorMove; // Already imported at the top of the module
|
|
||||||
let filter_start_pos = (trigger_pos.0, trigger_pos.1 + 1);
|
let filter_start_pos = (trigger_pos.0, trigger_pos.1 + 1);
|
||||||
editor.move_cursor(CursorMove::Jump(filter_start_pos.0 as u16, filter_start_pos.1 as u16));
|
editor.move_cursor(CursorMove::Jump(filter_start_pos.0 as u16, filter_start_pos.1 as u16));
|
||||||
for _ in 0..filter_len {
|
for _ in 0..filter_len {
|
||||||
|
|||||||
@@ -75,7 +75,6 @@ pub struct EventHandler {
|
|||||||
pub command_mode: bool,
|
pub command_mode: bool,
|
||||||
pub command_input: String,
|
pub command_input: String,
|
||||||
pub command_message: String,
|
pub command_message: String,
|
||||||
pub is_edit_mode: bool,
|
|
||||||
pub edit_mode_cooldown: bool,
|
pub edit_mode_cooldown: bool,
|
||||||
pub ideal_cursor_column: usize,
|
pub ideal_cursor_column: usize,
|
||||||
pub key_sequence_tracker: KeySequenceTracker,
|
pub key_sequence_tracker: KeySequenceTracker,
|
||||||
@@ -106,7 +105,6 @@ impl EventHandler {
|
|||||||
command_mode: false,
|
command_mode: false,
|
||||||
command_input: String::new(),
|
command_input: String::new(),
|
||||||
command_message: String::new(),
|
command_message: String::new(),
|
||||||
is_edit_mode: false,
|
|
||||||
edit_mode_cooldown: false,
|
edit_mode_cooldown: false,
|
||||||
ideal_cursor_column: 0,
|
ideal_cursor_column: 0,
|
||||||
key_sequence_tracker: KeySequenceTracker::new(400),
|
key_sequence_tracker: KeySequenceTracker::new(400),
|
||||||
@@ -396,7 +394,6 @@ impl EventHandler {
|
|||||||
key_event,
|
key_event,
|
||||||
config,
|
config,
|
||||||
app_state,
|
app_state,
|
||||||
&mut self.is_edit_mode,
|
|
||||||
buffer_state,
|
buffer_state,
|
||||||
client_clone,
|
client_clone,
|
||||||
sender_clone,
|
sender_clone,
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ pub fn render_ui(
|
|||||||
router: &mut Router,
|
router: &mut Router,
|
||||||
buffer_state: &BufferState,
|
buffer_state: &BufferState,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_event_handler_edit_mode: bool,
|
|
||||||
event_handler_command_input: &str,
|
event_handler_command_input: &str,
|
||||||
event_handler_command_mode_active: bool,
|
event_handler_command_mode_active: bool,
|
||||||
event_handler_command_message: &str,
|
event_handler_command_message: &str,
|
||||||
@@ -96,7 +95,7 @@ pub fn render_ui(
|
|||||||
Page::Admin(state) => crate::components::admin::admin_panel::render_admin_panel(
|
Page::Admin(state) => crate::components::admin::admin_panel::render_admin_panel(
|
||||||
f,
|
f,
|
||||||
app_state,
|
app_state,
|
||||||
&mut AuthState::default(), // TODO: later move AuthState into Router
|
&mut AuthState::default(),
|
||||||
state,
|
state,
|
||||||
main_content_area,
|
main_content_area,
|
||||||
theme,
|
theme,
|
||||||
@@ -109,7 +108,6 @@ pub fn render_ui(
|
|||||||
theme,
|
theme,
|
||||||
app_state,
|
app_state,
|
||||||
state,
|
state,
|
||||||
is_event_handler_edit_mode,
|
|
||||||
),
|
),
|
||||||
Page::AddTable(state) => render_add_table(
|
Page::AddTable(state) => render_add_table(
|
||||||
f,
|
f,
|
||||||
@@ -117,7 +115,6 @@ pub fn render_ui(
|
|||||||
theme,
|
theme,
|
||||||
app_state,
|
app_state,
|
||||||
state,
|
state,
|
||||||
is_event_handler_edit_mode,
|
|
||||||
),
|
),
|
||||||
Page::Form(state) => {
|
Page::Form(state) => {
|
||||||
let (sidebar_area, form_actual_area) =
|
let (sidebar_area, form_actual_area) =
|
||||||
@@ -189,7 +186,6 @@ pub fn render_ui(
|
|||||||
&mut chunk_idx,
|
&mut chunk_idx,
|
||||||
current_dir,
|
current_dir,
|
||||||
theme,
|
theme,
|
||||||
is_event_handler_edit_mode,
|
|
||||||
current_fps,
|
current_fps,
|
||||||
app_state,
|
app_state,
|
||||||
navigation_state,
|
navigation_state,
|
||||||
|
|||||||
@@ -544,7 +544,7 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
|
|
||||||
if let Page::Form(form_state) = &mut router.current {
|
if let Page::Form(form_state) = &mut router.current {
|
||||||
if !table_just_switched {
|
if !table_just_switched {
|
||||||
if position_changed && !event_handler.is_edit_mode {
|
if position_changed && !matches!(app_state.form_editor.as_ref().map(|e| e.mode()), Some(canvas::AppMode::Edit)) {
|
||||||
position_logic_needs_redraw = true;
|
position_logic_needs_redraw = true;
|
||||||
|
|
||||||
if let Some(form_state) = app_state.form_state_mut() {
|
if let Some(form_state) = app_state.form_state_mut() {
|
||||||
@@ -582,7 +582,7 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
form_state.current_cursor_pos =
|
form_state.current_cursor_pos =
|
||||||
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
}
|
}
|
||||||
} else if !position_changed && !event_handler.is_edit_mode {
|
} else if !position_changed && !matches!(app_state.form_editor.as_ref().map(|e| e.mode()), Some(canvas::AppMode::Edit)) {
|
||||||
if let Some(form_state) = app_state.form_state_mut() {
|
if let Some(form_state) = app_state.form_state_mut() {
|
||||||
let current_input_str = form_state.get_current_input();
|
let current_input_str = form_state.get_current_input();
|
||||||
let current_input_len = current_input_str.chars().count();
|
let current_input_len = current_input_str.chars().count();
|
||||||
@@ -597,7 +597,7 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if let Page::Register(state) = &mut router.current {
|
} else if let Page::Register(state) = &mut router.current {
|
||||||
if !event_handler.is_edit_mode {
|
if !matches!(app_state.form_editor.as_ref().map(|e| e.mode()), Some(canvas::AppMode::Edit)) {
|
||||||
let current_input = state.get_current_input();
|
let current_input = state.get_current_input();
|
||||||
let max_cursor_pos =
|
let max_cursor_pos =
|
||||||
if !current_input.is_empty() { current_input.len() - 1 } else { 0 };
|
if !current_input.is_empty() { current_input.len() - 1 } else { 0 };
|
||||||
@@ -605,7 +605,7 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
}
|
}
|
||||||
} else if let Page::Login(state) = &mut router.current {
|
} else if let Page::Login(state) = &mut router.current {
|
||||||
if !event_handler.is_edit_mode {
|
if !matches!(app_state.form_editor.as_ref().map(|e| e.mode()), Some(canvas::AppMode::Edit)) {
|
||||||
let current_input = state.get_current_input();
|
let current_input = state.get_current_input();
|
||||||
let max_cursor_pos =
|
let max_cursor_pos =
|
||||||
if !current_input.is_empty() { current_input.len() - 1 } else { 0 };
|
if !current_input.is_empty() { current_input.len() - 1 } else { 0 };
|
||||||
@@ -688,7 +688,6 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
&mut router,
|
&mut router,
|
||||||
&buffer_state,
|
&buffer_state,
|
||||||
&theme,
|
&theme,
|
||||||
event_handler.is_edit_mode,
|
|
||||||
&event_handler.command_input,
|
&event_handler.command_input,
|
||||||
event_handler.command_mode,
|
event_handler.command_mode,
|
||||||
&event_handler.command_message,
|
&event_handler.command_message,
|
||||||
|
|||||||
Reference in New Issue
Block a user