use crate::editor::char_search::{SearchDirection, SearchType};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TextObjectScope {
Inner,
Around,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum EditorMode {
#[default]
Insert,
Normal,
Operator(char),
CharSearch(SearchDirection, SearchType),
OperatorCharSearch(char, usize, SearchDirection, SearchType),
TextObject(char, TextObjectScope),
}
impl EditorMode {
fn char_search_display(dir: SearchDirection, st: SearchType) -> char {
match dir {
SearchDirection::Forward => match st {
SearchType::Find => 'f',
SearchType::Till => 't',
},
SearchDirection::Backward => match st {
SearchType::Find => 'F',
SearchType::Till => 'T',
},
}
}
pub fn display(&self) -> String {
match self {
EditorMode::Insert => "INSERT".to_string(),
EditorMode::Normal => "NORMAL".to_string(),
EditorMode::Operator(op) => format!("OPERATOR({})", op),
EditorMode::CharSearch(dir, st) => {
format!("CHAR({})", Self::char_search_display(*dir, *st))
}
EditorMode::OperatorCharSearch(op, _, dir, st) => {
format!("{}{}…", op, Self::char_search_display(*dir, *st))
}
EditorMode::TextObject(op, scope) => {
let scope_char = match scope {
TextObjectScope::Inner => 'i',
TextObjectScope::Around => 'a',
};
format!("{}{}…", op, scope_char)
}
}
}
}
#[cfg(test)]
#[path = "mode_tests.rs"]
mod mode_tests;