removing compatibility code fully, we are now fresh without compat layer. We compiled successfuly
This commit is contained in:
@@ -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<S: CanvasState + Autocomple
|
||||
return Ok(result);
|
||||
}
|
||||
|
||||
// 2. Handle generic actions and add auto-trigger logic
|
||||
let result = handle_generic_canvas_action(action.clone(), state, ideal_cursor_column, config).await?;
|
||||
|
||||
// 2. Handle generic actions using the new dispatcher directly
|
||||
let result = ActionDispatcher::dispatch_with_config(action.clone(), state, ideal_cursor_column, config).await?;
|
||||
|
||||
// 3. AUTO-TRIGGER LOGIC: Check if we should activate/deactivate autocomplete
|
||||
if let Some(cfg) = config {
|
||||
println!("{:?}, {}", action, cfg.should_auto_trigger_autocomplete());
|
||||
@@ -39,27 +39,27 @@ pub async fn execute_canvas_action_with_autocomplete<S: CanvasState + Autocomple
|
||||
println!("AUTO-T on Ins");
|
||||
let current_field = state.current_field();
|
||||
let current_input = state.get_current_input();
|
||||
|
||||
|
||||
if state.supports_autocomplete(current_field)
|
||||
&& !state.is_autocomplete_active()
|
||||
&& current_input.len() >= 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
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<S: CanvasState>(
|
||||
action: CanvasAction,
|
||||
state: &mut S,
|
||||
ideal_cursor_column: &mut usize,
|
||||
config: Option<&CanvasConfig>,
|
||||
) -> Result<ActionResult> {
|
||||
// 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<S: CanvasState>(
|
||||
action: CanvasAction,
|
||||
state: &mut S,
|
||||
ideal_cursor_column: &mut usize,
|
||||
config: Option<&CanvasConfig>,
|
||||
) -> Result<ActionResult> {
|
||||
// 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"))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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<S: CanvasState>(
|
||||
action: CanvasAction,
|
||||
state: &mut S,
|
||||
ideal_cursor_column: &mut usize,
|
||||
config: Option<&CanvasConfig>,
|
||||
) -> anyhow::Result<ActionResult> {
|
||||
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
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user