Skip to main content

hjkl_vim/
operator.rs

1/// Operator identity carried by the reducer. Kept independent of
2/// `hjkl-engine` so `hjkl-vim` has no upstream dependency.
3///
4/// Only the five operators that can be entered directly from Normal mode via
5/// bare `d` / `y` / `c` / `>` / `<` are listed here. Case operators
6/// (`gu` / `gU` / `g~`) and Reflow (`gq`) are deferred to chunk 2c-v;
7/// Fold (`zf`) does not enter bare op-pending so it is omitted entirely.
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub enum OperatorKind {
10    /// `d` — delete.
11    Delete,
12    /// `y` — yank.
13    Yank,
14    /// `c` — change (delete + enter Insert mode).
15    Change,
16    /// `>` — indent.
17    Indent,
18    /// `<` — outdent.
19    Outdent,
20}
21
22impl OperatorKind {
23    /// The doubled-letter char for this operator (`dd`, `yy`, `cc`, `>>`, `<<`).
24    pub(crate) fn double_char(self) -> char {
25        match self {
26            OperatorKind::Delete => 'd',
27            OperatorKind::Yank => 'y',
28            OperatorKind::Change => 'c',
29            OperatorKind::Indent => '>',
30            OperatorKind::Outdent => '<',
31        }
32    }
33}