diff options
author | Kirill Chibisov <contact@kchibisov.com> | 2022-07-11 22:54:28 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-11 22:54:28 +0300 |
commit | 40bbdce6de8775b7bbc3f9a5731337d1dd05d195 (patch) | |
tree | bd8ed857ebd4a68744b6ca3e3557fc5fa179d281 /alacritty/src | |
parent | e09ff0b4b0654fd6dbcf8c0bdc73fdb9ae7d8016 (diff) | |
download | r-alacritty-40bbdce6de8775b7bbc3f9a5731337d1dd05d195.tar.gz r-alacritty-40bbdce6de8775b7bbc3f9a5731337d1dd05d195.tar.bz2 r-alacritty-40bbdce6de8775b7bbc3f9a5731337d1dd05d195.zip |
Fix hyperlinks not being keyboard actionable
This fixes a typo in 694a52b which was filtering all hyperlinks, except
only duplicated ones when opening them with keyboard.
Co-authored-by: Christian Duerr <contact@christianduerr.com>
Diffstat (limited to 'alacritty/src')
-rw-r--r-- | alacritty/src/display/hint.rs | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/alacritty/src/display/hint.rs b/alacritty/src/display/hint.rs index a59f2bc7..887840e9 100644 --- a/alacritty/src/display/hint.rs +++ b/alacritty/src/display/hint.rs @@ -79,7 +79,7 @@ impl HintState { // Add escape sequence hyperlinks. if hint.content.hyperlinks { - self.matches.extend(visible_unique_hyperlink_iter(term)); + self.matches.extend(visible_unique_hyperlinks_iter(term)); } // Add visible regex matches. @@ -298,7 +298,7 @@ pub fn visible_regex_match_iter<'a, T>( } /// Iterate over all visible hyperlinks, yanking only unique ones. -pub fn visible_unique_hyperlink_iter<T>(term: &Term<T>) -> impl Iterator<Item = Match> + '_ { +pub fn visible_unique_hyperlinks_iter<T>(term: &Term<T>) -> impl Iterator<Item = Match> + '_ { let mut display_iter = term.grid().display_iter().peekable(); // Avoid creating hints for the same hyperlinks, but from a different places. @@ -308,7 +308,7 @@ pub fn visible_unique_hyperlink_iter<T>(term: &Term<T>) -> impl Iterator<Item = // Find the start of the next unique hyperlink. let (cell, hyperlink) = display_iter.find_map(|cell| { let hyperlink = cell.hyperlink()?; - unique_hyperlinks.contains(&hyperlink).then(|| { + (!unique_hyperlinks.contains(&hyperlink)).then(|| { unique_hyperlinks.insert(hyperlink.clone()); (cell, hyperlink) }) @@ -582,6 +582,7 @@ impl<'a, T> Iterator for HintPostProcessor<'a, T> { #[cfg(test)] mod tests { + use alacritty_terminal::ansi::Handler; use alacritty_terminal::index::{Column, Line}; use alacritty_terminal::term::test::mock_term; @@ -642,4 +643,41 @@ mod tests { assert_eq!(count, 0); } + + #[test] + fn collect_unique_hyperlinks() { + let mut term = mock_term("000\r\n111"); + term.goto(Line(0), Column(0)); + + let hyperlink_foo = Hyperlink::new(Some("1"), "foo"); + let hyperlink_bar = Hyperlink::new(Some("2"), "bar"); + + // Create 2 hyperlinks on the first line. + term.set_hyperlink(Some(hyperlink_foo.clone())); + term.input('b'); + term.input('a'); + term.set_hyperlink(Some(hyperlink_bar.clone())); + term.input('r'); + term.set_hyperlink(Some(hyperlink_foo.clone())); + term.goto(Line(1), Column(0)); + + // Ditto for the second line. + term.set_hyperlink(Some(hyperlink_foo)); + term.input('b'); + term.input('a'); + term.set_hyperlink(Some(hyperlink_bar)); + term.input('r'); + term.set_hyperlink(None); + + let mut unique_hyperlinks = visible_unique_hyperlinks_iter(&term); + assert_eq!( + Some(Match::new(Point::new(Line(0), Column(0)), Point::new(Line(0), Column(1)))), + unique_hyperlinks.next() + ); + assert_eq!( + Some(Match::new(Point::new(Line(0), Column(2)), Point::new(Line(0), Column(2)))), + unique_hyperlinks.next() + ); + assert_eq!(None, unique_hyperlinks.next()); + } } |