From cd3620692b1c7a64379ebc0226c6a1d4e05a0962 Mon Sep 17 00:00:00 2001 From: Kirill Bulatov Date: Fri, 21 Jul 2023 11:28:56 +0300 Subject: [PATCH] Do not highlight fake URLs in terminal --- crates/terminal/src/terminal.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index 3a64cff24f870eab763addb8936daa14e285fda3..f81af1319e504fa0cf529de418ec88f07c023d41 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -74,7 +74,7 @@ const DEBUG_LINE_HEIGHT: f32 = 5.; lazy_static! { // Regex Copied from alacritty's ui_config.rs - static ref URL_REGEX: RegexSearch = RegexSearch::new("(ipfs:|ipns:|magnet:|mailto:|gemini:|gopher:|https:|http:|news:|file:|git:|ssh:|ftp:)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>\"\\s{-}\\^⟨⟩`]+").unwrap(); + static ref URL_REGEX: RegexSearch = RegexSearch::new(r#"(ipfs:|ipns:|magnet:|mailto:|gemini://|gopher://|https://|http://|news:|file://|git://|ssh:|ftp://)[^\u{0000}-\u{001F}\u{007F}-\u{009F}<>"\s{-}\^⟨⟩`]+"#).unwrap(); static ref WORD_REGEX: RegexSearch = RegexSearch::new("[\\w.:/@-]+").unwrap(); } @@ -875,8 +875,10 @@ impl Terminal { } else if let Some(word_match) = regex_match_at(term, point, &WORD_REGEX) { let maybe_url_or_path = term.bounds_to_string(*word_match.start(), *word_match.end()); - let is_url = regex_match_at(term, point, &URL_REGEX).is_some(); - + let is_url = match regex_match_at(term, point, &URL_REGEX) { + Some(url_match) => url_match == word_match, + None => false, + }; Some((maybe_url_or_path, is_url, word_match)) } else { None