alma 0.1.1

A Bevy-native modal text editor with Vim-style navigation.
Documentation
//! Rejection taxonomies for ECS owner-boundary messages.

use crate::{
    buffer::BufferEditError,
    ecs::components::buffer::{BufferEntity, ViewEntity},
    text_stream::TextRevision,
};

/// Reasons a buffer edit request can be rejected by the buffer owner.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum BufferEditRejectionReason {
    /// The requested buffer target does not exist.
    MissingTarget {
        /// Missing buffer entity.
        target: BufferEntity,
    },
    /// The requested edit violated buffer text invariants.
    InvalidEdit {
        /// Buffer edit validation error.
        error: BufferEditError,
    },
    /// A revision-guarded edit was derived from stale buffer text.
    StaleRevision {
        /// Revision observed when the edit was derived.
        expected: TextRevision,
        /// Revision present at the buffer owner boundary.
        actual: TextRevision,
    },
}

/// Reasons an edit-history request can be rejected by the buffer owner.
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum EditHistoryRejectionReason {
    /// The requested buffer target does not exist.
    MissingTarget {
        /// Missing buffer entity.
        target: BufferEntity,
    },
    /// The target buffer has no undo history to replay.
    EmptyUndoStack,
    /// The target buffer has no redo history to replay.
    EmptyRedoStack,
    /// Replaying the retained edit violated buffer text invariants.
    InvalidEdit {
        /// Buffer edit validation error.
        error: BufferEditError,
    },
}

/// Reasons a plugin proposal decision can be rejected.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum PluginProposalDecisionRejectionReason {
    /// The proposal is no longer pending in the proposal lane.
    UnknownProposal {
        /// Requested proposal id.
        id: crate::ecs::events::edit::PluginProposalId,
    },
}

/// Reasons a command request can be rejected before command execution.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CommandRejectionReason {
    /// The requested buffer target does not exist.
    MissingTarget {
        /// Missing buffer entity.
        target: BufferEntity,
    },
}

/// Boundary reasons for rejecting cursor movement requests.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum CursorMoveRejectionReason {
    /// The requested editor view entity does not exist at the owner boundary.
    MissingTarget {
        /// View entity that could not be resolved.
        target: ViewEntity,
    },
    /// The requested view exists but its backing buffer entity does not.
    MissingBuffer {
        /// View entity whose backing buffer is stale.
        target: ViewEntity,
        /// Buffer entity that could not be resolved.
        buffer: BufferEntity,
    },
}

/// Boundary reasons for rejecting Vim input before interpretation.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum VimInputRejectionReason {
    /// The focused view exists but its backing buffer entity does not.
    MissingBuffer {
        /// View entity whose backing buffer is stale.
        target: ViewEntity,
        /// Buffer entity that could not be resolved.
        buffer: BufferEntity,
    },
    /// Insert-mode text exceeded the per-frame adapter payload bound.
    InsertPayloadTooLarge {
        /// View entity whose input was rejected.
        target: ViewEntity,
        /// Rejected input byte length.
        rejected_byte_len: usize,
        /// Maximum accepted input byte length for one frame.
        max_byte_len: usize,
    },
    /// Count-expanded paste text exceeded the adapter payload bound.
    PastePayloadTooLarge {
        /// View entity whose input was rejected.
        target: ViewEntity,
        /// Rejected paste byte length.
        rejected_byte_len: usize,
        /// Maximum accepted paste byte length for one request.
        max_byte_len: usize,
    },
}

/// Reasons a status request can be rejected by the status owner.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum StatusRejectionReason {
    /// The requested editor view entity does not exist.
    MissingTarget {
        /// View entity that could not be resolved.
        target: ViewEntity,
    },
}

/// Reasons a focus request can be rejected by the focus owner.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum FocusRejectionReason {
    /// The requested editor view entity does not exist.
    MissingTarget {
        /// View entity that could not be resolved.
        target: ViewEntity,
    },
}

/// Reasons a viewport intent can be rejected by the layout owner.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum ViewportRejectionReason {
    /// The requested editor view entity does not exist.
    MissingTarget {
        /// View entity that could not be resolved.
        target: ViewEntity,
    },
    /// The requested view exists but its backing buffer entity does not.
    MissingBuffer {
        /// View entity whose backing buffer is stale.
        target: ViewEntity,
        /// Buffer entity that could not be resolved.
        buffer: BufferEntity,
    },
}