From 82090c60ca76c08c5ea20833ce26e331e4afc869 Mon Sep 17 00:00:00 2001 From: Liang Kui Date: Fri, 23 Aug 2024 15:58:53 +0800 Subject: [PATCH] Able to resolve URLs with query params in terminal (#16724) image Release Notes: - URLs with query parameters are now clickable in the terminal --- crates/terminal/src/terminal.rs | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index b9eddd8bb3..de83d54d91 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -851,38 +851,27 @@ impl Terminal { let url = link.unwrap().uri().to_owned(); let url_match = min_index..=max_index; + Some((url, true, url_match)) + } else if let Some(url_match) = regex_match_at(term, point, &mut self.url_regex) { + let url = term.bounds_to_string(*url_match.start(), *url_match.end()); Some((url, true, url_match)) } else if let Some(word_match) = regex_match_at(term, point, &mut self.word_regex) { - let maybe_url_or_path = - term.bounds_to_string(*word_match.start(), *word_match.end()); - let original_match = word_match.clone(); + let file_path = term.bounds_to_string(*word_match.start(), *word_match.end()); + let (sanitized_match, sanitized_word) = - if maybe_url_or_path.starts_with('[') && maybe_url_or_path.ends_with(']') { + if file_path.starts_with('[') && file_path.ends_with(']') { ( Match::new( word_match.start().add(term, Boundary::Cursor, 1), word_match.end().sub(term, Boundary::Cursor, 1), ), - maybe_url_or_path[1..maybe_url_or_path.len() - 1].to_owned(), + file_path[1..file_path.len() - 1].to_owned(), ) } else { - (word_match, maybe_url_or_path) + (word_match, file_path) }; - let is_url = match regex_match_at(term, point, &mut self.url_regex) { - Some(url_match) => { - // `]` is a valid symbol in the `file://` URL, so the regex match will include it - // consider that when ensuring that the URL match is the same as the original word - if sanitized_match == original_match { - url_match == sanitized_match - } else { - url_match.start() == sanitized_match.start() - && url_match.end() == original_match.end() - } - } - None => false, - }; - Some((sanitized_word, is_url, sanitized_match)) + Some((sanitized_word, false, sanitized_match)) } else { None };