Add a VisualBlock mode

Instead of trying to extend the Mode::Visual special case, just split
out into three different modes.
This commit is contained in:
Conrad Irwin 2023-08-15 08:48:01 -06:00
parent 404b1aa65a
commit 1cc0798aea
16 changed files with 94 additions and 90 deletions

View file

@ -9,14 +9,16 @@ use crate::motion::Motion;
pub enum Mode {
Normal,
Insert,
Visual { line: bool },
Visual,
VisualLine,
VisualBlock,
}
impl Mode {
pub fn is_visual(&self) -> bool {
match self {
Mode::Normal | Mode::Insert => false,
Mode::Visual { .. } => true,
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => true,
}
}
}
@ -74,7 +76,7 @@ impl VimState {
CursorShape::Underscore
}
}
Mode::Visual { .. } => CursorShape::Block,
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => CursorShape::Block,
Mode::Insert => CursorShape::Bar,
}
}
@ -89,7 +91,7 @@ impl VimState {
pub fn clip_at_line_ends(&self) -> bool {
match self.mode {
Mode::Insert | Mode::Visual { .. } => false,
Mode::Insert | Mode::Visual | Mode::VisualLine | Mode::VisualBlock => false,
Mode::Normal => true,
}
}
@ -101,7 +103,7 @@ impl VimState {
"vim_mode",
match self.mode {
Mode::Normal => "normal",
Mode::Visual { .. } => "visual",
Mode::Visual | Mode::VisualLine | Mode::VisualBlock => "visual",
Mode::Insert => "insert",
},
);