#[non_exhaustive]
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum CanvasAction {
MoveLeft,
MoveRight,
MoveUp,
MoveDown,
MoveWordNext,
MoveWordPrev,
MoveWordEnd,
MoveWordEndPrev,
MoveBigWordNext,
MoveBigWordPrev,
MoveBigWordEnd,
MoveBigWordEndPrev,
MoveLineStart,
MoveLineEnd,
NextField,
PrevField,
MoveFirstLine,
MoveLastLine,
InsertChar(char),
DeleteBackward,
DeleteForward,
Undo,
Redo,
TriggerSuggestions,
SuggestionUp,
SuggestionDown,
SelectSuggestion,
ExitSuggestions,
Custom(String),
EnterEditMode,
EnterEditModeAfter,
ExitEditMode,
EnterHighlightMode,
EnterHighlightModeLinewise,
ExitHighlightMode,
OpenLineBelow,
OpenLineAbove,
}
#[non_exhaustive]
#[derive(Debug, Clone)]
pub enum ActionResult {
Success,
Message(String),
Error(String),
}
impl ActionResult {
pub fn success() -> Self {
Self::Success
}
pub fn success_with_message(msg: &str) -> Self {
Self::Message(msg.to_string())
}
pub fn handled_by_app(msg: &str) -> Self {
Self::Message(msg.to_string())
}
pub fn error(msg: &str) -> Self {
Self::Error(msg.to_string())
}
pub fn is_success(&self) -> bool {
matches!(self, Self::Success | Self::Message(_))
}
pub fn message(&self) -> Option<&str> {
match self {
Self::Message(msg) | Self::Error(msg) => Some(msg),
Self::Success => None,
}
}
}
impl CanvasAction {
pub fn description(&self) -> &'static str {
match self {
Self::MoveLeft => "move left",
Self::MoveRight => "move right",
Self::MoveUp => "move up",
Self::MoveDown => "move down",
Self::MoveWordNext => "next word",
Self::MoveWordPrev => "previous word",
Self::MoveWordEnd => "word end",
Self::MoveWordEndPrev => "previous word end",
Self::MoveBigWordNext => "next big word",
Self::MoveBigWordPrev => "previous big word",
Self::MoveBigWordEnd => "big word end",
Self::MoveBigWordEndPrev => "previous big word end",
Self::MoveLineStart => "line start",
Self::MoveLineEnd => "line end",
Self::NextField => "next field",
Self::PrevField => "previous field",
Self::MoveFirstLine => "first field",
Self::MoveLastLine => "last field",
Self::InsertChar(_c) => "insert character",
Self::DeleteBackward => "delete backward",
Self::DeleteForward => "delete forward",
Self::Undo => "undo",
Self::Redo => "redo",
Self::TriggerSuggestions => "trigger suggestions",
Self::SuggestionUp => "suggestion up",
Self::SuggestionDown => "suggestion down",
Self::SelectSuggestion => "select suggestion",
Self::ExitSuggestions => "exit suggestions",
Self::Custom(_name) => "custom action",
Self::EnterEditMode => "enter edit mode",
Self::EnterEditModeAfter => "enter append mode (a)",
Self::ExitEditMode => "exit edit mode",
Self::EnterHighlightMode => "enter visual mode",
Self::EnterHighlightModeLinewise => "enter linewise visual mode",
Self::ExitHighlightMode => "exit visual mode",
Self::OpenLineBelow => "open line below (o)",
Self::OpenLineAbove => "open line above (O)",
}
}
pub fn movement_actions() -> Vec<CanvasAction> {
vec![
Self::MoveLeft,
Self::MoveRight,
Self::MoveUp,
Self::MoveDown,
Self::MoveWordNext,
Self::MoveWordPrev,
Self::MoveWordEnd,
Self::MoveWordEndPrev,
Self::MoveBigWordNext,
Self::MoveBigWordPrev,
Self::MoveBigWordEnd,
Self::MoveBigWordEndPrev,
Self::MoveLineStart,
Self::MoveLineEnd,
Self::NextField,
Self::PrevField,
Self::MoveFirstLine,
Self::MoveLastLine,
]
}
pub fn editing_actions() -> Vec<CanvasAction> {
vec![
Self::InsertChar(' '), Self::DeleteBackward,
Self::DeleteForward,
]
}
pub fn suggestions_actions() -> Vec<CanvasAction> {
vec![
Self::TriggerSuggestions,
Self::SuggestionUp,
Self::SuggestionDown,
Self::SelectSuggestion,
Self::ExitSuggestions,
]
}
pub fn is_editing_action(&self) -> bool {
matches!(
self,
Self::InsertChar(_) | Self::DeleteBackward | Self::DeleteForward
)
}
pub fn is_movement_action(&self) -> bool {
matches!(
self,
Self::MoveLeft
| Self::MoveRight
| Self::MoveUp
| Self::MoveDown
| Self::MoveWordNext
| Self::MoveWordPrev
| Self::MoveWordEnd
| Self::MoveWordEndPrev
| Self::MoveBigWordNext
| Self::MoveBigWordPrev
| Self::MoveBigWordEnd
| Self::MoveBigWordEndPrev
| Self::MoveLineStart
| Self::MoveLineEnd
| Self::NextField
| Self::PrevField
| Self::MoveFirstLine
| Self::MoveLastLine
)
}
}