diff --git a/yazi-config/src/keymap/control.rs b/yazi-config/src/keymap/control.rs index 539afc75..456cc7fa 100644 --- a/yazi-config/src/keymap/control.rs +++ b/yazi-config/src/keymap/control.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, collections::VecDeque, sync::LazyLock}; +use std::{borrow::Cow, collections::VecDeque, sync::OnceLock}; use regex::Regex; use serde::Deserialize; @@ -6,7 +6,7 @@ use yazi_shared::event::Cmd; use super::Key; -static RE: LazyLock = LazyLock::new(|| Regex::new(r"\s+").unwrap()); +static RE: OnceLock = OnceLock::new(); #[derive(Debug, Default, Deserialize)] pub struct Control { @@ -26,11 +26,14 @@ impl Control { pub fn on(&self) -> String { self.on.iter().map(ToString::to_string).collect() } pub fn run(&self) -> String { - RE.replace_all(&self.run.iter().map(|c| c.to_string()).collect::>().join("; "), " ") + RE.get_or_init(|| Regex::new(r"\s+").unwrap()) + .replace_all(&self.run.iter().map(|c| c.to_string()).collect::>().join("; "), " ") .into_owned() } - pub fn desc(&self) -> Option> { self.desc.as_ref().map(|s| RE.replace_all(s, " ")) } + pub fn desc(&self) -> Option> { + self.desc.as_ref().map(|s| RE.get_or_init(|| Regex::new(r"\s+").unwrap()).replace_all(s, " ")) + } pub fn desc_or_run(&self) -> Cow { self.desc().unwrap_or_else(|| self.run().into()) }