feat(config): add word_separator option
This commit is contained in:
parent
17ffe488fe
commit
3df0df6fc7
|
@ -91,6 +91,10 @@ pub trait Config: Send {
|
|||
// application is missing some key events.
|
||||
fn key_delay(&self) -> Option<usize>;
|
||||
|
||||
// Chars that when pressed mark the start and end of a word.
|
||||
// Examples of this are . or ,
|
||||
fn word_separators(&self) -> Vec<String>;
|
||||
|
||||
fn is_match<'a>(&self, app: &AppProperties<'a>) -> bool;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,6 +34,7 @@ pub(crate) struct ParsedConfig {
|
|||
pub toggle_key: Option<String>,
|
||||
pub paste_shortcut: Option<String>,
|
||||
pub disable_x11_fast_inject: Option<bool>,
|
||||
pub word_separators: Option<Vec<String>>,
|
||||
|
||||
pub pre_paste_delay: Option<usize>,
|
||||
pub restore_clipboard_delay: Option<usize>,
|
||||
|
|
|
@ -69,6 +69,9 @@ pub(crate) struct YAMLConfig {
|
|||
#[serde(default)]
|
||||
pub backspace_delay: Option<usize>,
|
||||
|
||||
#[serde(default)]
|
||||
pub word_separators: Option<Vec<String>>,
|
||||
|
||||
// Include/Exclude
|
||||
#[serde(default)]
|
||||
pub includes: Option<Vec<String>>,
|
||||
|
@ -127,6 +130,7 @@ impl TryFrom<YAMLConfig> for ParsedConfig {
|
|||
disable_x11_fast_inject: yaml_config.disable_x11_fast_inject,
|
||||
inject_delay: yaml_config.inject_delay,
|
||||
key_delay: yaml_config.key_delay.or(yaml_config.backspace_delay),
|
||||
word_separators: yaml_config.word_separators,
|
||||
|
||||
pre_paste_delay: yaml_config.pre_paste_delay,
|
||||
restore_clipboard_delay: yaml_config.restore_clipboard_delay,
|
||||
|
@ -169,6 +173,7 @@ mod tests {
|
|||
inject_delay: 10
|
||||
key_delay: 20
|
||||
backspace_delay: 30
|
||||
word_separators: ["'", "."]
|
||||
|
||||
use_standard_includes: true
|
||||
includes: ["test1"]
|
||||
|
@ -204,6 +209,7 @@ mod tests {
|
|||
pre_paste_delay: Some(300),
|
||||
|
||||
toggle_key: Some("CTRL".to_string()),
|
||||
word_separators: Some(vec!["'".to_owned(), ".".to_owned()]),
|
||||
|
||||
use_standard_includes: Some(true),
|
||||
includes: Some(vec!["test1".to_string()]),
|
||||
|
|
|
@ -17,7 +17,16 @@
|
|||
* along with espanso. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
use super::{AppProperties, Backend, Config, ToggleKey, default::{DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY, DEFAULT_SHORTCUT_EVENT_DELAY}, parse::ParsedConfig, path::calculate_paths, util::os_matches};
|
||||
use super::{
|
||||
default::{
|
||||
DEFAULT_CLIPBOARD_THRESHOLD, DEFAULT_PRE_PASTE_DELAY, DEFAULT_RESTORE_CLIPBOARD_DELAY,
|
||||
DEFAULT_SHORTCUT_EVENT_DELAY,
|
||||
},
|
||||
parse::ParsedConfig,
|
||||
path::calculate_paths,
|
||||
util::os_matches,
|
||||
AppProperties, Backend, Config, ToggleKey,
|
||||
};
|
||||
use crate::{counter::next_id, merge};
|
||||
use anyhow::Result;
|
||||
use log::error;
|
||||
|
@ -193,11 +202,17 @@ impl Config for ResolvedConfig {
|
|||
}
|
||||
|
||||
fn restore_clipboard_delay(&self) -> usize {
|
||||
self.parsed.restore_clipboard_delay.unwrap_or(DEFAULT_RESTORE_CLIPBOARD_DELAY)
|
||||
self
|
||||
.parsed
|
||||
.restore_clipboard_delay
|
||||
.unwrap_or(DEFAULT_RESTORE_CLIPBOARD_DELAY)
|
||||
}
|
||||
|
||||
fn paste_shortcut_event_delay(&self) -> usize {
|
||||
self.parsed.paste_shortcut_event_delay.unwrap_or(DEFAULT_SHORTCUT_EVENT_DELAY)
|
||||
self
|
||||
.parsed
|
||||
.paste_shortcut_event_delay
|
||||
.unwrap_or(DEFAULT_SHORTCUT_EVENT_DELAY)
|
||||
}
|
||||
|
||||
fn paste_shortcut(&self) -> Option<String> {
|
||||
|
@ -215,6 +230,19 @@ impl Config for ResolvedConfig {
|
|||
fn key_delay(&self) -> Option<usize> {
|
||||
self.parsed.key_delay
|
||||
}
|
||||
|
||||
fn word_separators(&self) -> Vec<String> {
|
||||
self.parsed.word_separators.clone().unwrap_or(vec![
|
||||
" ".to_string(),
|
||||
",".to_string(),
|
||||
".".to_string(),
|
||||
"?".to_string(),
|
||||
"!".to_string(),
|
||||
"\r".to_string(),
|
||||
"\n".to_string(),
|
||||
(22u8 as char).to_string(),
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
impl ResolvedConfig {
|
||||
|
@ -283,6 +311,7 @@ impl ResolvedConfig {
|
|||
toggle_key,
|
||||
inject_delay,
|
||||
key_delay,
|
||||
word_separators,
|
||||
includes,
|
||||
excludes,
|
||||
extra_includes,
|
||||
|
|
|
@ -327,6 +327,10 @@ impl Config for LegacyInteropConfig {
|
|||
Some(self.config.backspace_delay.try_into().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
fn word_separators(&self) -> Vec<String> {
|
||||
self.config.word_separators.iter().map(|c| String::from(*c)).collect()
|
||||
}
|
||||
}
|
||||
|
||||
struct LegacyMatchGroup {
|
||||
|
|
Loading…
Reference in New Issue
Block a user