use std::{borrow::Cow, fmt};
use reovim_kernel::api::v1::{CommandId, ModuleId};
pub const MODULE: ModuleId = ModuleId::new("vim");
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct OperatorId {
module: ModuleId,
name: Cow<'static, str>,
}
impl OperatorId {
#[must_use]
pub const fn new(module: ModuleId, name: &'static str) -> Self {
Self {
module,
name: Cow::Borrowed(name),
}
}
#[must_use]
pub fn from_qualified(qualified: String) -> Self {
let (module_str, name_str) = if let Some(idx) = qualified.find(':') {
(qualified[..idx].to_string(), qualified[idx + 1..].to_string())
} else {
("unknown".to_string(), qualified)
};
Self {
module: ModuleId::from_string(module_str),
name: Cow::Owned(name_str),
}
}
#[must_use]
pub const fn module(&self) -> &ModuleId {
&self.module
}
#[must_use]
pub fn name(&self) -> &str {
&self.name
}
#[must_use]
pub fn name_owned(&self) -> Cow<'static, str> {
self.name.clone()
}
}
impl fmt::Display for OperatorId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}:{}", self.module, self.name)
}
}
pub const DELETE: OperatorId = OperatorId::new(MODULE, "delete");
pub const YANK: OperatorId = OperatorId::new(MODULE, "yank");
pub const CHANGE: OperatorId = OperatorId::new(MODULE, "change");
pub const LOWERCASE: OperatorId = OperatorId::new(MODULE, "lowercase");
pub const UPPERCASE: OperatorId = OperatorId::new(MODULE, "uppercase");
pub const TOGGLE_CASE_OP: OperatorId = OperatorId::new(MODULE, "toggle-case");
pub const ENTER_INSERT: CommandId = CommandId::new(MODULE, "enter-insert");
pub const ENTER_INSERT_AFTER: CommandId = CommandId::new(MODULE, "enter-insert-after");
pub const ENTER_INSERT_EOL: CommandId = CommandId::new(MODULE, "enter-insert-eol");
pub const ENTER_INSERT_BOL: CommandId = CommandId::new(MODULE, "enter-insert-bol");
pub const OPEN_LINE_BELOW: CommandId = CommandId::new(MODULE, "open-line-below");
pub const OPEN_LINE_ABOVE: CommandId = CommandId::new(MODULE, "open-line-above");
pub const EXIT_INSERT: CommandId = CommandId::new(MODULE, "exit-insert");
pub const ENTER_VISUAL: CommandId = CommandId::new(MODULE, "enter-visual");
pub const ENTER_VISUAL_LINE: CommandId = CommandId::new(MODULE, "enter-visual-line");
pub const ENTER_VISUAL_BLOCK: CommandId = CommandId::new(MODULE, "enter-visual-block");
pub const EXIT_VISUAL: CommandId = CommandId::new(MODULE, "exit-visual");
pub const ENTER_COMMANDLINE: CommandId = CommandId::new(MODULE, "enter-commandline");
pub const CANCEL_COMMANDLINE: CommandId = CommandId::new(MODULE, "cancel-commandline");
pub const EXIT_COMMANDLINE: CommandId = CommandId::new(MODULE, "exit-commandline");
pub const CMDLINE_CURSOR_LEFT: CommandId = CommandId::new(MODULE, "cmdline-cursor-left");
pub const CMDLINE_CURSOR_RIGHT: CommandId = CommandId::new(MODULE, "cmdline-cursor-right");
pub const CMDLINE_CURSOR_HOME: CommandId = CommandId::new(MODULE, "cmdline-cursor-home");
pub const CMDLINE_CURSOR_END: CommandId = CommandId::new(MODULE, "cmdline-cursor-end");
pub const CMDLINE_DELETE_CHAR: CommandId = CommandId::new(MODULE, "cmdline-delete-char");
pub const CMDLINE_BACKSPACE: CommandId = CommandId::new(MODULE, "cmdline-backspace");
pub const CMDLINE_DELETE_WORD: CommandId = CommandId::new(MODULE, "cmdline-delete-word");
pub const CMDLINE_DELETE_TO_START: CommandId = CommandId::new(MODULE, "cmdline-delete-to-start");
pub const CMDLINE_HISTORY_UP: CommandId = CommandId::new(MODULE, "cmdline-history-up");
pub const CMDLINE_HISTORY_DOWN: CommandId = CommandId::new(MODULE, "cmdline-history-down");
pub const CMDLINE_COMPLETE_NEXT: CommandId = CommandId::new(MODULE, "cmdline-complete-next");
pub const CMDLINE_COMPLETE_PREV: CommandId = CommandId::new(MODULE, "cmdline-complete-prev");
pub const ENTER_WINDOW_MODE: CommandId = CommandId::new(MODULE, "enter-window-mode");
pub const ENTER_REPLACE_MODE: CommandId = CommandId::new(MODULE, "enter-replace-mode");
pub const REPLACE_BACKSPACE: CommandId = CommandId::new(MODULE, "replace-backspace");
pub const CANCEL_TO_NORMAL: CommandId = CommandId::new(MODULE, "cancel-to-normal");
pub const ENTER_SEARCH_FORWARD: CommandId = CommandId::new(MODULE, "enter-search-forward");
pub const ENTER_SEARCH_BACKWARD: CommandId = CommandId::new(MODULE, "enter-search-backward");
pub const EXECUTE_FIND_CHAR: CommandId = CommandId::new(MODULE, "execute-find-char");
pub const VISUAL_SWAP_ANCHOR: CommandId = CommandId::new(MODULE, "visual-swap-anchor");
pub const TOGGLE_VISUAL_CHAR: CommandId = CommandId::new(MODULE, "toggle-visual-char");
pub const TOGGLE_VISUAL_LINE: CommandId = CommandId::new(MODULE, "toggle-visual-line");
pub const TOGGLE_VISUAL_BLOCK: CommandId = CommandId::new(MODULE, "toggle-visual-block");
pub const RESELECT_LAST: CommandId = CommandId::new(MODULE, "reselect-last");
pub const DELETE_SELECTION: CommandId = CommandId::new(MODULE, "delete-selection");
pub const YANK_SELECTION: CommandId = CommandId::new(MODULE, "yank-selection");
pub const CHANGE_SELECTION: CommandId = CommandId::new(MODULE, "change-selection");
pub const INDENT_SELECTION: CommandId = CommandId::new(MODULE, "indent-selection");
pub const DEDENT_SELECTION: CommandId = CommandId::new(MODULE, "dedent-selection");
pub const CHANGE_LINE: CommandId = CommandId::new(MODULE, "change-line");
pub const CHANGE_TO_EOL: CommandId = CommandId::new(MODULE, "change-to-eol");
pub const DOT_REPEAT: CommandId = CommandId::new(MODULE, "dot-repeat");
pub const PLAY_MACRO: CommandId = CommandId::new(MODULE, "play-macro");
pub const REPEAT_MACRO: CommandId = CommandId::new(MODULE, "repeat-macro");
pub const SESSION_DETACH: CommandId = CommandId::new(MODULE, "session-detach");
pub const SESSION_SERVERS: CommandId = CommandId::new(MODULE, "session-servers");
pub const SESSION_KILL_SERVER: CommandId = CommandId::new(MODULE, "session-kill-server");
pub const VISUAL_SWAP_CORNER: CommandId = CommandId::new(MODULE, "visual-swap-corner");
pub const TOGGLE_CASE_SELECTION: CommandId = CommandId::new(MODULE, "toggle-case-selection");
pub const LOWERCASE_SELECTION: CommandId = CommandId::new(MODULE, "lowercase-selection");
pub const UPPERCASE_SELECTION: CommandId = CommandId::new(MODULE, "uppercase-selection");
pub const JOIN_SELECTION: CommandId = CommandId::new(MODULE, "join-selection");
pub const COMMAND_WITH_SELECTION: CommandId = CommandId::new(MODULE, "command-with-selection");
pub const VISUAL_NOOP: CommandId = CommandId::new(MODULE, "visual-noop");
pub const VISUAL_INSERT_START: CommandId = CommandId::new(MODULE, "visual-insert-start");
pub const VISUAL_INSERT_END: CommandId = CommandId::new(MODULE, "visual-insert-end");
pub const BLOCK_INSERT_START: CommandId = CommandId::new(MODULE, "block-insert-start");
pub const BLOCK_INSERT_END: CommandId = CommandId::new(MODULE, "block-insert-end");
pub const INNER_WORD: CommandId = CommandId::new(MODULE, "inner-word");
pub const INNER_WORD_BIG: CommandId = CommandId::new(MODULE, "inner-word-big");
pub const INNER_DOUBLE_QUOTE: CommandId = CommandId::new(MODULE, "inner-double-quote");
pub const INNER_SINGLE_QUOTE: CommandId = CommandId::new(MODULE, "inner-single-quote");
pub const INNER_BACKTICK: CommandId = CommandId::new(MODULE, "inner-backtick");
pub const INNER_PAREN: CommandId = CommandId::new(MODULE, "inner-paren");
pub const INNER_BRACKET: CommandId = CommandId::new(MODULE, "inner-bracket");
pub const INNER_BRACE: CommandId = CommandId::new(MODULE, "inner-brace");
pub const INNER_ANGLE: CommandId = CommandId::new(MODULE, "inner-angle");
pub const INNER_TAG: CommandId = CommandId::new(MODULE, "inner-tag");
pub const INNER_SENTENCE: CommandId = CommandId::new(MODULE, "inner-sentence");
pub const INNER_PARAGRAPH: CommandId = CommandId::new(MODULE, "inner-paragraph");
pub const AROUND_WORD: CommandId = CommandId::new(MODULE, "around-word");
pub const AROUND_WORD_BIG: CommandId = CommandId::new(MODULE, "around-word-big");
pub const AROUND_DOUBLE_QUOTE: CommandId = CommandId::new(MODULE, "around-double-quote");
pub const AROUND_SINGLE_QUOTE: CommandId = CommandId::new(MODULE, "around-single-quote");
pub const AROUND_BACKTICK: CommandId = CommandId::new(MODULE, "around-backtick");
pub const AROUND_PAREN: CommandId = CommandId::new(MODULE, "around-paren");
pub const AROUND_BRACKET: CommandId = CommandId::new(MODULE, "around-bracket");
pub const AROUND_BRACE: CommandId = CommandId::new(MODULE, "around-brace");
pub const AROUND_ANGLE: CommandId = CommandId::new(MODULE, "around-angle");
pub const AROUND_TAG: CommandId = CommandId::new(MODULE, "around-tag");
pub const AROUND_SENTENCE: CommandId = CommandId::new(MODULE, "around-sentence");
pub const AROUND_PARAGRAPH: CommandId = CommandId::new(MODULE, "around-paragraph");
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn operator_id_name_owned_static() {
let owned = DELETE.name_owned();
assert_eq!(owned, "delete");
}
#[test]
fn operator_id_name_owned_dynamic() {
let op = OperatorId::from_qualified("mymod:custom-op".to_string());
let owned = op.name_owned();
assert_eq!(owned, "custom-op");
}
}