Able to resolve URLs with query params in terminal (#16724)

<img width="207" alt="image"
src="https://github.com/user-attachments/assets/aa7d8de1-313b-4aae-a6c6-00b442b76fb8">

Release Notes:

- URLs with query parameters are now clickable in the terminal
This commit is contained in:
Liang Kui 2024-08-23 15:58:53 +08:00 committed by GitHub
parent bdf26fe38a
commit 82090c60ca
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
};