add fallback onNextKey

adds a variant of on_next_key callbacks that are only called when no other
mapping matches a key
This commit is contained in:
Pascal Kuthe 2024-03-03 23:22:30 +01:00 committed by Michael Davis
parent 609c29bf7e
commit 66fb1e67c0
No known key found for this signature in database
2 changed files with 51 additions and 14 deletions

View file

@ -87,6 +87,11 @@ use grep_searcher::{sinks, BinaryDetection, SearcherBuilder};
use ignore::{DirEntry, WalkBuilder, WalkState};
pub type OnKeyCallback = Box<dyn FnOnce(&mut Context, KeyEvent)>;
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum OnKeyCallbackKind {
PseudoPending,
Fallback,
}
pub struct Context<'a> {
pub register: Option<char>,
@ -94,7 +99,7 @@ pub struct Context<'a> {
pub editor: &'a mut Editor,
pub callback: Vec<crate::compositor::Callback>,
pub on_next_key_callback: Option<OnKeyCallback>,
pub on_next_key_callback: Option<(OnKeyCallback, OnKeyCallbackKind)>,
pub jobs: &'a mut Jobs,
}
@ -120,7 +125,19 @@ impl Context<'_> {
&mut self,
on_next_key_callback: impl FnOnce(&mut Context, KeyEvent) + 'static,
) {
self.on_next_key_callback = Some(Box::new(on_next_key_callback));
self.on_next_key_callback = Some((
Box::new(on_next_key_callback),
OnKeyCallbackKind::PseudoPending,
));
}
#[inline]
pub fn on_next_key_fallback(
&mut self,
on_next_key_callback: impl FnOnce(&mut Context, KeyEvent) + 'static,
) {
self.on_next_key_callback =
Some((Box::new(on_next_key_callback), OnKeyCallbackKind::Fallback));
}
#[inline]