diff --git a/canvas/src/autocomplete/actions.rs b/canvas/src/autocomplete/actions.rs index 2c4403a..b7e3c51 100644 --- a/canvas/src/autocomplete/actions.rs +++ b/canvas/src/autocomplete/actions.rs @@ -1,9 +1,9 @@ -// canvas/src/autocomplete/actions.rs +// src/autocomplete/actions.rs use crate::canvas::state::{CanvasState, ActionContext}; use crate::autocomplete::state::AutocompleteCanvasState; use crate::canvas::actions::types::{CanvasAction, ActionResult}; -use crate::canvas::actions::edit::handle_generic_canvas_action; +use crate::dispatcher::ActionDispatcher; // NEW: Use dispatcher directly use crate::config::CanvasConfig; use anyhow::Result; @@ -26,9 +26,9 @@ pub async fn execute_canvas_action_with_autocomplete= 1 + && current_input.len() >= 1 { println!("ACT AUTOC"); state.activate_autocomplete(); } } - + CanvasAction::NextField | CanvasAction::PrevField => { println!("AUTO-T on nav"); let current_field = state.current_field(); - + if state.supports_autocomplete(current_field) && !state.is_autocomplete_active() { state.activate_autocomplete(); } else if !state.supports_autocomplete(current_field) && state.is_autocomplete_active() { state.deactivate_autocomplete(); } } - + _ => {} // No auto-trigger for other actions } } diff --git a/canvas/src/canvas/actions/edit.rs b/canvas/src/canvas/actions/edit.rs deleted file mode 100644 index ab2682d..0000000 --- a/canvas/src/canvas/actions/edit.rs +++ /dev/null @@ -1,62 +0,0 @@ -// src/canvas/actions/edit.rs -// COMPATIBILITY LAYER - maintains old API while using new handler system - -use crate::canvas::state::{CanvasState, ActionContext}; -use crate::canvas::actions::types::{CanvasAction, ActionResult}; -use crate::config::CanvasConfig; -use anyhow::Result; - -/// BACKWARD COMPATIBILITY: Execute a typed canvas action on any CanvasState implementation -/// This maintains the old API while routing to the new mode-aware system -pub async fn execute_canvas_action( - action: CanvasAction, - state: &mut S, - ideal_cursor_column: &mut usize, - config: Option<&CanvasConfig>, -) -> Result { - // Route to new dispatcher system - crate::dispatcher::ActionDispatcher::dispatch_with_config( - action, - state, - ideal_cursor_column, - config, - ).await -} - -/// BACKWARD COMPATIBILITY: Handle core canvas actions with full type safety -/// This function is kept for backward compatibility with autocomplete and other modules -pub async fn handle_generic_canvas_action( - action: CanvasAction, - state: &mut S, - ideal_cursor_column: &mut usize, - config: Option<&CanvasConfig>, -) -> Result { - // Check for feature-specific handling first - let context = ActionContext { - key_code: None, - ideal_cursor_column: *ideal_cursor_column, - current_input: state.get_current_input().to_string(), - current_field: state.current_field(), - }; - - if let Some(result) = state.handle_feature_action(&action, &context) { - return Ok(ActionResult::HandledByFeature(result)); - } - - // Route to appropriate mode handler based on current mode - match state.current_mode() { - crate::canvas::modes::AppMode::Edit => { - crate::canvas::actions::handlers::handle_edit_action(action, state, ideal_cursor_column, config).await - } - crate::canvas::modes::AppMode::ReadOnly => { - crate::canvas::actions::handlers::handle_readonly_action(action, state, ideal_cursor_column, config).await - } - crate::canvas::modes::AppMode::Highlight => { - crate::canvas::actions::handlers::handle_highlight_action(action, state, ideal_cursor_column, config).await - } - crate::canvas::modes::AppMode::General | crate::canvas::modes::AppMode::Command => { - // These modes might not handle canvas actions directly - Ok(ActionResult::success_with_message("Mode does not handle canvas actions")) - } - } -} diff --git a/canvas/src/canvas/actions/mod.rs b/canvas/src/canvas/actions/mod.rs index 9a97642..6beba1b 100644 --- a/canvas/src/canvas/actions/mod.rs +++ b/canvas/src/canvas/actions/mod.rs @@ -3,10 +3,6 @@ pub mod types; pub mod movement; pub mod handlers; -pub mod edit; // Compatibility layer -// Re-export the main types for convenience +// Re-export the main types pub use types::{CanvasAction, ActionResult}; - -// Re-export from edit.rs for backward compatibility -pub use edit::{execute_canvas_action, handle_generic_canvas_action}; diff --git a/canvas/src/canvas/mod.rs b/canvas/src/canvas/mod.rs index d4f9fbd..e68fac2 100644 --- a/canvas/src/canvas/mod.rs +++ b/canvas/src/canvas/mod.rs @@ -1,15 +1,18 @@ // src/canvas/mod.rs pub mod actions; -pub mod modes; pub mod gui; -pub mod theme; +pub mod modes; pub mod state; +pub mod theme; // Re-export commonly used canvas types pub use actions::{CanvasAction, ActionResult}; pub use modes::{AppMode, ModeManager, HighlightState}; pub use state::{CanvasState, ActionContext}; +// Re-export the main entry point +pub use crate::dispatcher::execute_canvas_action; + #[cfg(feature = "gui")] pub use theme::CanvasTheme; diff --git a/canvas/src/dispatcher.rs b/canvas/src/dispatcher.rs index 1b7cbd5..09a284d 100644 --- a/canvas/src/dispatcher.rs +++ b/canvas/src/dispatcher.rs @@ -7,6 +7,16 @@ use crate::canvas::modes::AppMode; use crate::config::CanvasConfig; use crossterm::event::{KeyCode, KeyModifiers}; +/// Main entry point for executing canvas actions +pub async fn execute_canvas_action( + action: CanvasAction, + state: &mut S, + ideal_cursor_column: &mut usize, + config: Option<&CanvasConfig>, +) -> anyhow::Result { + ActionDispatcher::dispatch_with_config(action, state, ideal_cursor_column, config).await +} + /// High-level action dispatcher that routes actions to mode-specific handlers pub struct ActionDispatcher; @@ -87,7 +97,7 @@ impl ActionDispatcher { let mut results = Vec::new(); for action in actions { let result = Self::dispatch(action, state, ideal_cursor_column).await?; - let is_success = result.is_success(); // Check success before moving + let is_success = result.is_success(); results.push(result); // Stop on first error diff --git a/canvas/src/lib.rs b/canvas/src/lib.rs index c25e34b..26c5a40 100644 --- a/canvas/src/lib.rs +++ b/canvas/src/lib.rs @@ -3,3 +3,9 @@ pub mod canvas; pub mod autocomplete; pub mod config; pub mod dispatcher; + +// Re-export the main API for easy access +pub use dispatcher::{execute_canvas_action, ActionDispatcher}; +pub use canvas::actions::{CanvasAction, ActionResult}; +pub use canvas::state::{CanvasState, ActionContext}; +pub use canvas::modes::{AppMode, HighlightState, ModeManager};