feat(core): wire up backspace_limit option
This commit is contained in:
parent
ddbfa06881
commit
05920fbebc
|
@ -129,9 +129,7 @@ impl<'a> super::engine::dispatch::executor::clipboard_injector::ClipboardParamsP
|
|||
}
|
||||
}
|
||||
|
||||
impl<'a> super::engine::dispatch::executor::InjectParamsProvider
|
||||
for ConfigManager<'a>
|
||||
{
|
||||
impl<'a> super::engine::dispatch::executor::InjectParamsProvider for ConfigManager<'a> {
|
||||
fn get(&self) -> super::engine::dispatch::executor::InjectParams {
|
||||
let active = self.active();
|
||||
super::engine::dispatch::executor::InjectParams {
|
||||
|
@ -141,3 +139,9 @@ impl<'a> super::engine::dispatch::executor::InjectParamsProvider
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> crate::engine::process::MatcherMiddlewareConfigProvider for ConfigManager<'a> {
|
||||
fn max_history_size(&self) -> usize {
|
||||
self.default().backspace_limit()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -141,6 +141,7 @@ pub fn initialize_and_spawn(
|
|||
&sequencer,
|
||||
&path_provider,
|
||||
disable_options,
|
||||
&config_manager,
|
||||
);
|
||||
|
||||
let event_injector = EventInjectorAdapter::new(&*injector, &config_manager);
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
use log::trace;
|
||||
|
||||
use super::{DisableOptions, MatchFilter, MatchInfoProvider, MatchSelector, Matcher, Middleware, Multiplexer, PathProvider, Processor, Renderer, middleware::{
|
||||
use super::{DisableOptions, MatchFilter, MatchInfoProvider, MatchSelector, Matcher, MatcherMiddlewareConfigProvider, Middleware, Multiplexer, PathProvider, Processor, Renderer, middleware::{
|
||||
match_select::MatchSelectMiddleware, matcher::MatcherMiddleware, multiplex::MultiplexMiddleware,
|
||||
render::RenderMiddleware, action::{ActionMiddleware, EventSequenceProvider}, cursor_hint::CursorHintMiddleware, cause::CauseCompensateMiddleware,
|
||||
delay_modifiers::{DelayForModifierReleaseMiddleware, ModifierStatusProvider}, markdown::MarkdownMiddleware,
|
||||
|
@ -45,6 +45,7 @@ impl<'a> DefaultProcessor<'a> {
|
|||
event_sequence_provider: &'a dyn EventSequenceProvider,
|
||||
path_provider: &'a dyn PathProvider,
|
||||
disable_options: DisableOptions,
|
||||
matcher_options_provider: &'a dyn MatcherMiddlewareConfigProvider,
|
||||
) -> DefaultProcessor<'a> {
|
||||
Self {
|
||||
event_queue: VecDeque::new(),
|
||||
|
@ -52,7 +53,7 @@ impl<'a> DefaultProcessor<'a> {
|
|||
Box::new(PastEventsDiscardMiddleware::new()),
|
||||
Box::new(DisableMiddleware::new(disable_options)),
|
||||
Box::new(IconStatusMiddleware::new()),
|
||||
Box::new(MatcherMiddleware::new(matchers)),
|
||||
Box::new(MatcherMiddleware::new(matchers, matcher_options_provider)),
|
||||
Box::new(ContextMenuMiddleware::new()),
|
||||
Box::new(MatchSelectMiddleware::new(match_filter, match_selector)),
|
||||
Box::new(CauseCompensateMiddleware::new()),
|
||||
|
|
|
@ -30,19 +30,26 @@ use crate::engine::{
|
|||
process::{Matcher, MatcherEvent},
|
||||
};
|
||||
|
||||
const MAX_HISTORY: usize = 3; // TODO: get as parameter
|
||||
pub trait MatcherMiddlewareConfigProvider {
|
||||
fn max_history_size(&self) -> usize;
|
||||
}
|
||||
|
||||
pub struct MatcherMiddleware<'a, State> {
|
||||
matchers: &'a [&'a dyn Matcher<'a, State>],
|
||||
|
||||
matcher_states: RefCell<VecDeque<Vec<State>>>,
|
||||
|
||||
max_history_size: usize,
|
||||
}
|
||||
|
||||
impl<'a, State> MatcherMiddleware<'a, State> {
|
||||
pub fn new(matchers: &'a [&'a dyn Matcher<'a, State>]) -> Self {
|
||||
pub fn new(matchers: &'a [&'a dyn Matcher<'a, State>], options_provider: &'a dyn MatcherMiddlewareConfigProvider) -> Self {
|
||||
let max_history_size = options_provider.max_history_size();
|
||||
|
||||
Self {
|
||||
matchers,
|
||||
matcher_states: RefCell::new(VecDeque::new()),
|
||||
max_history_size,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -92,7 +99,7 @@ impl<'a, State> Middleware for MatcherMiddleware<'a, State> {
|
|||
}
|
||||
|
||||
matcher_states.push_back(new_states);
|
||||
if matcher_states.len() > MAX_HISTORY {
|
||||
if matcher_states.len() > self.max_history_size {
|
||||
matcher_states.pop_front();
|
||||
}
|
||||
|
||||
|
|
|
@ -96,6 +96,7 @@ pub use middleware::action::{MatchInfoProvider, EventSequenceProvider};
|
|||
pub use middleware::delay_modifiers::ModifierStatusProvider;
|
||||
pub use middleware::image_resolve::PathProvider;
|
||||
pub use middleware::disable::DisableOptions;
|
||||
pub use middleware::matcher::MatcherMiddlewareConfigProvider;
|
||||
|
||||
pub fn default<'a, MatcherState>(
|
||||
matchers: &'a [&'a dyn Matcher<'a, MatcherState>],
|
||||
|
@ -108,6 +109,7 @@ pub fn default<'a, MatcherState>(
|
|||
event_sequence_provider: &'a dyn EventSequenceProvider,
|
||||
path_provider: &'a dyn PathProvider,
|
||||
disable_options: DisableOptions,
|
||||
matcher_options_provider: &'a dyn MatcherMiddlewareConfigProvider,
|
||||
) -> impl Processor + 'a {
|
||||
default::DefaultProcessor::new(
|
||||
matchers,
|
||||
|
@ -120,5 +122,6 @@ pub fn default<'a, MatcherState>(
|
|||
event_sequence_provider,
|
||||
path_provider,
|
||||
disable_options,
|
||||
matcher_options_provider,
|
||||
)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user