diff options
Diffstat (limited to 'src/event/event_dispatch.rs')
-rw-r--r-- | src/event/event_dispatch.rs | 83 |
1 files changed, 52 insertions, 31 deletions
diff --git a/src/event/event_dispatch.rs b/src/event/event_dispatch.rs index 2a52714..a571cb3 100644 --- a/src/event/event_dispatch.rs +++ b/src/event/event_dispatch.rs @@ -2,9 +2,13 @@ use anyhow::Result; use tuikit::prelude::{Event, Key, MouseButton}; use crate::app::Status; -use crate::config::{Bindings, REFRESH_KEY}; +use crate::config::Bindings; use crate::event::event_exec::EventAction; -use crate::modes::{Display, Edit, InputSimple, MarkAction, Navigate}; +use crate::modes::{ + Display, Edit, InputCompleted, InputSimple, LeaveMode, MarkAction, Navigate, Search, +}; + +use super::FmEvents; /// Struct which mutates `tabs.selected().. /// Holds a mapping which can't be static since it's read from a config file. @@ -25,21 +29,25 @@ impl EventDispatcher { /// Only non keyboard events are dealt here directly. /// Keyboard events are configurable and are sent to specific functions /// which needs to know those keybindings. - pub fn dispatch(&self, status: &mut Status, ev: Event) -> Result<()> { + pub fn dispatch(&self, status: &mut Status, ev: FmEvents) -> Result<()> { match ev { - Event::Key(key) => self.match_key_event(status, key), - Event::Resize { width, height } => EventAction::resize(status, width, height), + FmEvents::Event(Event::Key(key)) => self.match_key_event(status, key), + FmEvents::Event(Event::Resize { width, height }) => { + EventAction::resize(status, width, height) + } + FmEvents::BulkExecute => EventAction::bulk_confirm(status), + FmEvents::Refresh => EventAction::refresh_if_needed(status), _ => Ok(()), } } fn match_key_event(&self, status: &mut Status, key: Key) -> Result<()> { match key { - Key::WheelUp(_, col, nb_of_scrolls) => { - EventAction::wheel_up(status, col, nb_of_scrolls)? + Key::WheelUp(row, col, nb_of_scrolls) => { + EventAction::wheel_up(status, row, col, nb_of_scrolls)? } - Key::WheelDown(_, col, nb_of_scrolls) => { - EventAction::wheel_down(status, col, nb_of_scrolls)? + Key::WheelDown(row, col, nb_of_scrolls) => { + EventAction::wheel_down(status, row, col, nb_of_scrolls)? } Key::SingleClick(MouseButton::Left, row, col) => { EventAction::left_click(status, &self.binds, row, col)? @@ -52,11 +60,6 @@ impl EventDispatcher { EventAction::context(status)? } - // reserved keybind which can't be bound to anything. - // using `Key::User(())` conflicts with skim internal which - // interpret this event as a signal(1) - REFRESH_KEY => EventAction::refresh_if_needed(status.current_tab_mut())?, - Key::Char(c) => self.char(status, c)?, key => self.key_matcher(status, key)?, }; @@ -71,21 +74,41 @@ impl EventDispatcher { } fn char(&self, status: &mut Status, c: char) -> Result<()> { - let tab = status.current_tab_mut(); - match tab.edit_mode { - Edit::InputSimple(InputSimple::Sort) => status.sort(c), - Edit::InputSimple(InputSimple::RegexMatch) => status.input_regex(c), - Edit::InputSimple(_) => status.menu.input_insert(c), - Edit::InputCompleted(_) => status.input_complete(c), - Edit::NeedConfirmation(confirmed_action) => status.confirm(c, confirmed_action), - Edit::Navigate(navigate) => Self::navigate_char(navigate, status, c), - Edit::Nothing if matches!(tab.display_mode, Display::Preview) => { - tab.reset_display_mode_and_view() + if status.focus.is_file() { + self.key_matcher(status, Key::Char(c)) + } else { + let tab = status.current_tab_mut(); + match tab.edit_mode { + Edit::InputSimple(InputSimple::Sort) => status.sort(c), + Edit::InputSimple(InputSimple::RegexMatch) => status.input_regex(c), + Edit::InputSimple(InputSimple::Filter) => status.input_filter(c), + Edit::InputSimple(_) => status.menu.input_insert(c), + Edit::InputCompleted(input_completed) => { + status.menu.input.insert(c); + if matches!(input_completed, InputCompleted::Search) { + Self::update_search(status)?; + LeaveMode::search(status, false)? + } + status.menu.input_complete(&mut status.tabs[status.index])?; + Ok(()) + } + Edit::NeedConfirmation(confirmed_action) => status.confirm(c, confirmed_action), + Edit::Navigate(navigate) => Self::navigate_char(navigate, status, c), + Edit::Nothing if matches!(tab.display_mode, Display::Preview) => { + tab.reset_display_mode_and_view() + } + Edit::Nothing => self.key_matcher(status, Key::Char(c)), } - Edit::Nothing => self.key_matcher(status, Key::Char(c)), } } + fn update_search(status: &mut Status) -> Result<()> { + if let Ok(search) = Search::new(&status.menu.input.string()) { + status.current_tab_mut().search = search; + }; + Ok(()) + } + fn navigate_char(navigate: Navigate, status: &mut Status, c: char) -> Result<()> { match navigate { Navigate::Trash if c == 'x' => status.menu.trash_delete_permanently(), @@ -95,14 +118,12 @@ impl EventDispatcher { Navigate::RemovableDevices if c == 'm' => status.menu.mount_removable(), Navigate::RemovableDevices if c == 'g' => status.go_to_removable(), Navigate::RemovableDevices if c == 'u' => status.menu.umount_removable(), - Navigate::Jump if c == ' ' => status.menu.remove_selected_flagged(), - Navigate::Jump if c == 'u' => status.clear_flags_and_reset_view(), - Navigate::Jump if c == 'x' => status.menu.delete_single_flagged(), - Navigate::Jump if c == 'X' => status.menu.trash_single_flagged(), - Navigate::Jump if c == 'f' => status.fuzzy_flags(), Navigate::Marks(MarkAction::Jump) => status.marks_jump_char(c), Navigate::Marks(MarkAction::New) => status.marks_new(c), - _ => status.current_tab_mut().reset_display_mode_and_view(), + _ => { + status.reset_edit_mode()?; + status.current_tab_mut().reset_display_mode_and_view() + } } } } |