move out of canvas properly fixed, now working everyhing properly well
This commit is contained in:
@@ -1,4 +1,6 @@
|
||||
// src/pages/admin_panel/add_logic/event.rs
|
||||
|
||||
use anyhow::Result;
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::movement::{move_focus, MovementAction};
|
||||
use crate::pages::admin_panel::add_logic::nav::SaveLogicResultSender;
|
||||
@@ -6,7 +8,8 @@ use crate::pages::admin_panel::add_logic::state::{AddLogicFocus, AddLogicFormSta
|
||||
use crate::components::common::text_editor::TextEditor;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::app::state::AppState;
|
||||
use canvas::DataProvider;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use canvas::{AppMode as CanvasMode, DataProvider};
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
/// Focus traversal order for non-canvas navigation
|
||||
@@ -19,7 +22,9 @@ const ADD_LOGIC_FOCUS_ORDER: [AddLogicFocus; 6] = [
|
||||
AddLogicFocus::CancelButton,
|
||||
];
|
||||
|
||||
/// Return true if the event was handled and UI should be redrawn.
|
||||
/// Handles all AddLogic page-specific events.
|
||||
/// Return a non-empty Ok(message) only when the page actually consumed the key,
|
||||
/// otherwise return Ok("") to let global handling proceed.
|
||||
pub fn handle_add_logic_event(
|
||||
key_event: KeyEvent,
|
||||
movement: Option<MovementAction>,
|
||||
@@ -28,16 +33,14 @@ pub fn handle_add_logic_event(
|
||||
add_logic_page: &mut AddLogicFormState,
|
||||
grpc_client: GrpcClient,
|
||||
save_logic_sender: SaveLogicResultSender,
|
||||
command_message: &mut String,
|
||||
) -> bool {
|
||||
) -> Result<EventOutcome> {
|
||||
// 1) Script editor fullscreen mode
|
||||
if add_logic_page.state.current_focus == AddLogicFocus::InsideScriptContent {
|
||||
match key_event.code {
|
||||
crossterm::event::KeyCode::Esc => {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Exited script editing.".to_string();
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok("Exited script editing.".to_string()));
|
||||
}
|
||||
_ => {
|
||||
let changed = {
|
||||
@@ -52,9 +55,9 @@ pub fn handle_add_logic_event(
|
||||
};
|
||||
if changed {
|
||||
add_logic_page.state.has_unsaved_changes = true;
|
||||
*command_message = "Script updated".to_string();
|
||||
return Ok(EventOutcome::Ok("Script updated".to_string()));
|
||||
}
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -68,32 +71,41 @@ pub fn handle_add_logic_event(
|
||||
);
|
||||
|
||||
if inside_canvas_inputs {
|
||||
if let Some(ma) = movement {
|
||||
let last_idx = add_logic_page.editor.data_provider().field_count().saturating_sub(1);
|
||||
let at_last = add_logic_page.editor.current_field() >= last_idx;
|
||||
if at_last && matches!(ma, MovementAction::Down | MovementAction::Next) {
|
||||
add_logic_page.state.last_canvas_field = last_idx;
|
||||
add_logic_page.state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
*command_message = "Moved to Script Preview".to_string();
|
||||
return true;
|
||||
// Only allow leaving the canvas with Down/Next when the form editor
|
||||
// is in ReadOnly mode. In Edit mode, keep focus inside the canvas.
|
||||
let in_edit_mode = add_logic_page.editor.mode() == CanvasMode::Edit;
|
||||
if !in_edit_mode {
|
||||
if let Some(ma) = movement {
|
||||
let last_idx = add_logic_page
|
||||
.editor
|
||||
.data_provider()
|
||||
.field_count()
|
||||
.saturating_sub(1);
|
||||
let at_last = add_logic_page.editor.current_field() >= last_idx;
|
||||
if at_last && matches!(ma, MovementAction::Down | MovementAction::Next) {
|
||||
add_logic_page.state.last_canvas_field = last_idx;
|
||||
add_logic_page.state.current_focus = AddLogicFocus::ScriptContentPreview;
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
return Ok(EventOutcome::Ok("Moved to Script Preview".to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match add_logic_page.handle_key_event(key_event) {
|
||||
canvas::keymap::KeyEventOutcome::Consumed(Some(msg)) => {
|
||||
add_logic_page.sync_from_editor();
|
||||
if !msg.is_empty() {
|
||||
*command_message = msg;
|
||||
}
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok(msg));
|
||||
}
|
||||
canvas::keymap::KeyEventOutcome::Consumed(None) => {
|
||||
add_logic_page.sync_from_editor();
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok("Input updated".into()));
|
||||
}
|
||||
canvas::keymap::KeyEventOutcome::Pending => {
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
canvas::keymap::KeyEventOutcome::NotMatched => {
|
||||
// fall through
|
||||
}
|
||||
canvas::keymap::KeyEventOutcome::Pending => return true,
|
||||
canvas::keymap::KeyEventOutcome::NotMatched => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +120,7 @@ pub fn handle_add_logic_event(
|
||||
| AddLogicFocus::InputTargetColumn
|
||||
| AddLogicFocus::InputDescription
|
||||
);
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
|
||||
match ma {
|
||||
@@ -116,20 +128,19 @@ pub fn handle_add_logic_event(
|
||||
AddLogicFocus::ScriptContentPreview => {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::InsideScriptContent;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
*command_message = "Fullscreen script editing. Esc to exit.".to_string();
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok(
|
||||
"Fullscreen script editing. Esc to exit.".to_string(),
|
||||
));
|
||||
}
|
||||
AddLogicFocus::SaveButton => {
|
||||
if let Some(msg) = add_logic_page.state.save_logic() {
|
||||
*command_message = msg;
|
||||
return Ok(EventOutcome::Ok(msg));
|
||||
} else {
|
||||
*command_message = "Saved (no changes)".to_string();
|
||||
return Ok(EventOutcome::Ok("Saved (no changes)".to_string()));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
AddLogicFocus::CancelButton => {
|
||||
*command_message = "Cancelled Add Logic".to_string();
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok("Cancelled Add Logic".to_string()));
|
||||
}
|
||||
_ => {}
|
||||
},
|
||||
@@ -137,13 +148,12 @@ pub fn handle_add_logic_event(
|
||||
if add_logic_page.state.current_focus == AddLogicFocus::ScriptContentPreview {
|
||||
add_logic_page.state.current_focus = AddLogicFocus::InputDescription;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
*command_message = "Back to Description".to_string();
|
||||
return true;
|
||||
return Ok(EventOutcome::Ok("Back to Description".to_string()));
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
false
|
||||
Ok(EventOutcome::Ok(String::new()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user