diff --git a/src/components/mod.rs b/src/components/mod.rs index bb0063ac..41e0b6f1 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -48,6 +48,7 @@ macro_rules! accessors { }; } +/// returns `true` if event was consumed pub fn event_pump( ev: Event, components: &mut [&mut dyn Component], @@ -61,6 +62,23 @@ pub fn event_pump( false } +/// helper fn to simplify delegating command +/// gathering down into child components +/// see `event_pump`,`accessors` +pub fn command_pump( + out: &mut Vec, + force_all: bool, + components: &[&dyn Component], +) { + for c in components { + if c.commands(out, force_all) != CommandBlocking::PassingOn + && !force_all + { + break; + } + } +} + #[derive(Copy, Clone)] pub enum ScrollType { Up, diff --git a/src/tabs/stashing.rs b/src/tabs/stashing.rs index 479e0146..cd1d8337 100644 --- a/src/tabs/stashing.rs +++ b/src/tabs/stashing.rs @@ -1,7 +1,8 @@ use crate::{ + accessors, components::{ - CommandBlocking, CommandInfo, Component, DrawableComponent, - FileTreeComponent, + command_pump, event_pump, CommandBlocking, CommandInfo, + Component, DrawableComponent, FileTreeComponent, }, keys, queue::{InternalEvent, NeedsUpdate, Queue}, @@ -36,6 +37,8 @@ pub struct Stashing { } impl Stashing { + accessors!(self, [index]); + /// pub fn new( sender: &Sender, @@ -162,7 +165,7 @@ impl Component for Stashing { out: &mut Vec, force_all: bool, ) -> CommandBlocking { - self.index.commands(out, force_all); + command_pump(out, force_all, self.components().as_slice()); out.push(CommandInfo::new( commands::STASHING_SAVE, @@ -189,9 +192,7 @@ impl Component for Stashing { fn event(&mut self, ev: crossterm::event::Event) -> bool { if self.visible { - let conusmed = self.index.event(ev); - - if conusmed { + if event_pump(ev, self.components_mut().as_mut_slice()) { return true; } diff --git a/src/tabs/status.rs b/src/tabs/status.rs index bb32aaf3..bf731a6a 100644 --- a/src/tabs/status.rs +++ b/src/tabs/status.rs @@ -1,8 +1,8 @@ use crate::{ accessors, components::{ - event_pump, ChangesComponent, CommandBlocking, CommandInfo, - Component, DiffComponent, DrawableComponent, + self, event_pump, ChangesComponent, CommandBlocking, + CommandInfo, Component, DiffComponent, DrawableComponent, FileTreeItemKind, }, keys, @@ -14,6 +14,7 @@ use asyncgit::{ sync::status::StatusType, AsyncDiff, AsyncNotification, AsyncStatus, DiffParams, StatusParams, }; +use components::command_pump; use crossbeam_channel::Sender; use crossterm::event::Event; use strings::commands; @@ -262,14 +263,11 @@ impl Component for Status { force_all: bool, ) -> CommandBlocking { if self.visible { - for c in self.components() { - if c.commands(out, force_all) - != CommandBlocking::PassingOn - && !force_all - { - break; - } - } + command_pump( + out, + force_all, + self.components().as_slice(), + ); { let focus_on_diff = self.focus == Focus::Diff; @@ -325,10 +323,7 @@ impl Component for Status { fn event(&mut self, ev: crossterm::event::Event) -> bool { if self.visible { - let conusmed = - event_pump(ev, self.components_mut().as_mut_slice()); - - if conusmed { + if event_pump(ev, self.components_mut().as_mut_slice()) { return true; }