From c6e4f9d04c14054cf2ea2c8728f2bd1d16353ef0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Fri, 20 Oct 2023 09:46:21 -0600 Subject: [PATCH] ViEditor: add passthrough mode (disables vi features) --- src/edit/vi.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/edit/vi.rs b/src/edit/vi.rs index 69e0403..e479d69 100644 --- a/src/edit/vi.rs +++ b/src/edit/vi.rs @@ -9,6 +9,7 @@ use crate::{ #[derive(Clone, Copy, Debug, Eq, PartialEq)] enum Mode { + Passthrough, Normal, Insert, Command, @@ -50,6 +51,15 @@ impl<'a> ViEditor<'a> { pub fn foreground_color(&self) -> Color { self.editor.foreground_color() } + + /// Set passthrough mode (true will turn off vi features) + pub fn set_passthrough(&mut self, passthrough: bool) { + if passthrough { + self.mode = Mode::Passthrough; + } else { + self.mode = Mode::Normal; + } + } } impl<'a> Edit for ViEditor<'a> { @@ -97,6 +107,7 @@ impl<'a> Edit for ViEditor<'a> { let old_mode = self.mode; match self.mode { + Mode::Passthrough => self.editor.action(font_system, action), Mode::Normal => match action { Action::Insert(c) => match c { // Enter insert mode after cursor @@ -369,6 +380,7 @@ impl<'a> Edit for ViEditor<'a> { cursor_glyph_opt(&self.cursor()) { let block_cursor = match self.mode { + Mode::Passthrough => false, Mode::Normal => true, Mode::Insert => false, _ => true, /*TODO: determine block cursor in other modes*/