From 581bd199bb8fde30c7a0ba660960a80d10f44652 Mon Sep 17 00:00:00 2001 From: Federico Terzi Date: Thu, 10 Jun 2021 21:14:35 +0200 Subject: [PATCH] feat(core): wire up word_separator option --- espanso/src/cli/worker/engine/mod.rs | 29 ++++--------------- .../process/middleware/matcher/rolling.rs | 21 +++++--------- 2 files changed, 13 insertions(+), 37 deletions(-) diff --git a/espanso/src/cli/worker/engine/mod.rs b/espanso/src/cli/worker/engine/mod.rs index a7ddcef..9764c68 100644 --- a/espanso/src/cli/worker/engine/mod.rs +++ b/espanso/src/cli/worker/engine/mod.rs @@ -26,33 +26,14 @@ use espanso_path::Paths; use espanso_ui::{event::UIEvent, UIRemote}; use log::info; -use crate::{ - cli::worker::{ - engine::{ - dispatch::executor::{ +use crate::{cli::worker::{engine::{dispatch::executor::{ clipboard_injector::ClipboardInjectorAdapter, context_menu::ContextMenuHandlerAdapter, event_injector::EventInjectorAdapter, icon::IconHandlerAdapter, key_injector::KeyInjectorAdapter, - }, - process::middleware::{ - image_resolve::PathProviderAdapter, - match_select::MatchSelectorAdapter, - matcher::{ - convert::MatchConverter, - regex::{RegexMatcherAdapter, RegexMatcherAdapterOptions}, - rolling::RollingMatcherAdapter, - }, - multiplex::MultiplexAdapter, - render::{ + }, process::middleware::{image_resolve::PathProviderAdapter, match_select::MatchSelectorAdapter, matcher::{convert::MatchConverter, regex::{RegexMatcherAdapter, RegexMatcherAdapterOptions}, rolling::{RollingMatcherAdapter, RollingMatcherAdapterOptions}}, multiplex::MultiplexAdapter, render::{ extension::{clipboard::ClipboardAdapter, form::FormProviderAdapter}, RendererAdapter, - }, - }, - }, - match_cache::MatchCache, - }, - engine::event::ExitMode, -}; + }}}, match_cache::MatchCache}, engine::event::ExitMode}; use super::secure_input::SecureInputEvent; @@ -94,7 +75,9 @@ pub fn initialize_and_spawn( vec![&detect_source, &exit_source, &ui_source, &secure_input_source]; let funnel = crate::engine::funnel::default(&sources); - let rolling_matcher = RollingMatcherAdapter::new(&match_converter.get_rolling_matches()); + let rolling_matcher = RollingMatcherAdapter::new(&match_converter.get_rolling_matches(), RollingMatcherAdapterOptions { + char_word_separators: config_manager.default().word_separators(), + }); let regex_matcher = RegexMatcherAdapter::new( &match_converter.get_regex_matches(), &RegexMatcherAdapterOptions { diff --git a/espanso/src/cli/worker/engine/process/middleware/matcher/rolling.rs b/espanso/src/cli/worker/engine/process/middleware/matcher/rolling.rs index af6404e..ec8975e 100644 --- a/espanso/src/cli/worker/engine/process/middleware/matcher/rolling.rs +++ b/espanso/src/cli/worker/engine/process/middleware/matcher/rolling.rs @@ -28,28 +28,21 @@ use crate::engine::{ use super::MatcherState; +pub struct RollingMatcherAdapterOptions { + pub char_word_separators: Vec, +} + pub struct RollingMatcherAdapter { matcher: RollingMatcher, } impl RollingMatcherAdapter { - pub fn new(matches: &[RollingMatch]) -> Self { - // TODO: load them from config - + pub fn new(matches: &[RollingMatch], options: RollingMatcherAdapterOptions) -> Self { let matcher = RollingMatcher::new( matches, RollingMatcherOptions { - char_word_separators: vec![ - " ".to_string(), - ",".to_string(), - ".".to_string(), - "?".to_string(), - "!".to_string(), - "\r".to_string(), - "\n".to_string(), - (22u8 as char).to_string(), - ], - key_word_separators: vec![], + char_word_separators: options.char_word_separators, + key_word_separators: vec![], // TODO? }, );