From 9ff25120a84c0c5d51df3221295faab51294a1ff Mon Sep 17 00:00:00 2001 From: sxyazi Date: Thu, 25 Jul 2024 07:53:01 +0800 Subject: [PATCH] Fix test --- yazi-config/src/keymap/control.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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()) }