alma 0.1.1

A Bevy-native modal text editor with Vim-style navigation.
Documentation
//! Buffer owner plugin wiring.

use super::{
    command::apply_command_requests,
    edit::{apply_buffer_edit_requests, apply_cursor_move_requests, apply_edit_history_requests},
    lifecycle::{LifecycleState, apply_lifecycle_requests},
    spawn::spawn_editor_buffer,
    status::apply_status_message_requests,
};
use crate::ecs::{schedules::EditorSet, schedules::EditorStartupSet};
use bevy::{
    app::AppExit,
    prelude::{App, IntoScheduleConfigs, Plugin, Startup, Update},
};

/// ECS plugin that owns editor buffer mutation boundaries.
#[derive(Clone, Copy, Debug, Default)]
pub struct BufferPlugin;

impl Plugin for BufferPlugin {
    fn build(&self, app: &mut App) {
        let _app = app
            .add_message::<AppExit>()
            .add_message::<crate::ecs::events::command::CommandRejected>()
            .init_resource::<LifecycleState>()
            .add_systems(
                Startup,
                spawn_editor_buffer.in_set(EditorStartupSet::Buffer),
            )
            .add_systems(
                Update,
                (
                    apply_buffer_edit_requests,
                    apply_edit_history_requests,
                    apply_command_requests,
                    apply_cursor_move_requests,
                    apply_status_message_requests,
                    apply_lifecycle_requests,
                )
                    .chain()
                    .in_set(EditorSet::Edit),
            );
    }
}