added EditorMode to the editor

macos-click-through
exoticus 4 years ago
parent a5abe769a6
commit 46cd882891

@ -114,6 +114,20 @@ pub enum WindowAnchor {
SouthEast,
}
#[derive(Debug)]
pub enum EditorMode {
// The set of modes reported will change in new versions of Nvim, for
// instance more sub-modes and temporary states might be represented as
// separate modes. (however we can safely do this as these are the main modes)
// for instance if we are in Terminal mode and even though status-line shows Terminal,
// we still get one of these as the _editor_ mode
Normal,
Insert,
Visual,
CmdLine,
Unknown(String),
}
#[derive(Debug)]
pub enum RedrawEvent {
SetTitle {
@ -126,6 +140,7 @@ pub enum RedrawEvent {
gui_option: GuiOption,
},
ModeChange {
mode: EditorMode,
mode_index: u64,
},
MouseOn,
@ -373,9 +388,17 @@ fn parse_option_set(option_set_arguments: Vec<Value>) -> Result<RedrawEvent> {
}
fn parse_mode_change(mode_change_arguments: Vec<Value>) -> Result<RedrawEvent> {
let [_mode, mode_index] = extract_values(mode_change_arguments, [Value::Nil, Value::Nil])?;
let [mode, mode_index] = extract_values(mode_change_arguments, [Value::Nil, Value::Nil])?;
let mode_name = parse_string(mode)?;
Ok(RedrawEvent::ModeChange {
mode: match mode_name.as_str() {
"normal" => EditorMode::Normal,
"insert" => EditorMode::Insert,
"visual" => EditorMode::Visual,
"cmdline_normal" => EditorMode::CmdLine,
_ => EditorMode::Unknown(mode_name),
},
mode_index: parse_u64(mode_index)?,
})
}

@ -10,7 +10,7 @@ use parking_lot::Mutex;
use skulpin::skia_safe::colors;
use unicode_segmentation::UnicodeSegmentation;
use crate::bridge::{GridLineCell, GuiOption, RedrawEvent};
use crate::bridge::{EditorMode, GridLineCell, GuiOption, RedrawEvent};
use crate::redraw_scheduler::REDRAW_SCHEDULER;
use crate::window::window_geometry_or_default;
pub use cursor::{Cursor, CursorMode, CursorShape};
@ -39,7 +39,8 @@ pub struct Editor {
pub default_style: Arc<Style>,
pub defined_styles: HashMap<u64, Arc<Style>>,
pub previous_style: Option<Arc<Style>>,
pub mode: u64,
pub mode_list: Vec<CursorMode>,
pub current_mode: EditorMode,
}
impl Editor {
@ -58,7 +59,8 @@ impl Editor {
))),
defined_styles: HashMap::new(),
previous_style: None,
mode: 0,
mode_list: Vec::new(),
current_mode: EditorMode::Unknown(String::from("")),
};
editor.grid.clear();
@ -68,11 +70,13 @@ impl Editor {
pub fn handle_redraw_event(&mut self, event: RedrawEvent) {
match event {
RedrawEvent::SetTitle { title } => self.title = title,
RedrawEvent::ModeInfoSet { cursor_modes } => self.cursor.mode_list = cursor_modes,
RedrawEvent::ModeInfoSet { cursor_modes } => self.mode_list = cursor_modes,
RedrawEvent::OptionSet { gui_option } => self.set_option(gui_option),
RedrawEvent::ModeChange { mode_index } => {
self.mode = mode_index;
self.cursor.change_mode(mode_index, &self.defined_styles)
RedrawEvent::ModeChange { mode, mode_index } => {
if let Some(cursor_mode) = self.mode_list.get(mode_index as usize) {
self.cursor.change_mode(cursor_mode, &self.defined_styles);
self.current_mode = mode
}
}
RedrawEvent::MouseOn => {
self.mouse_enabled = true;

Loading…
Cancel
Save