diff --git a/crates/terminal/src/terminal.rs b/crates/terminal/src/terminal.rs index aee760e..6da3ae8 100644 --- a/crates/terminal/src/terminal.rs +++ b/crates/terminal/src/terminal.rs @@ -2596,6 +2596,12 @@ impl Terminal { } } } + + // Ctrl/cmd-click opens links in mouse mode when this is enabled, so + // hovering with the modifier held has to highlight them as well. + if TerminalSettings::get_global(cx).open_links_in_mouse_mode { + self.schedule_find_hyperlink(e.modifiers, e.position, cx); + } } else { self.schedule_find_hyperlink(e.modifiers, e.position, cx); } @@ -5507,6 +5513,71 @@ mod tests { }); } + #[gpui::test] + async fn test_ctrl_hover_finds_hyperlink_in_mouse_mode(cx: &mut TestAppContext) { + let terminal = init_terminal_test(cx, b"Visit https://zed.dev/ for more\r\n"); + + terminal.update(cx, |terminal, cx| { + terminal.last_content.mode = Modes::MOUSE_REPORT_CLICK | Modes::MOUSE_MOTION; + + terminal.mouse_move( + &MouseMoveEvent { + position: point(px(80.0), px(10.0)), + pressed_button: None, + modifiers: Modifiers::secondary_key(), + }, + MouseInputMode::ReportToTerminal, + cx, + ); + + assert!( + any_event_matches!(terminal, InternalEvent::FindHyperlink(_, false)), + "ctrl+hover must look up the hyperlink under the pointer in mouse mode" + ); + let pty_writes = terminal.take_pty_write_log(); + assert_eq!( + pty_writes.len(), + 1, + "the motion must still be reported to the app, got {pty_writes:?}" + ); + }); + } + + #[gpui::test] + async fn test_ctrl_hover_in_mouse_mode_ignored_when_setting_disabled( + cx: &mut TestAppContext, + ) { + let terminal = init_terminal_test(cx, b"Visit https://zed.dev/ for more\r\n"); + + cx.update_global(|store: &mut settings::SettingsStore, cx| { + store.update_user_settings(cx, |settings| { + settings + .terminal + .get_or_insert_default() + .open_links_in_mouse_mode = Some(false); + }); + }); + + terminal.update(cx, |terminal, cx| { + terminal.last_content.mode = Modes::MOUSE_REPORT_CLICK | Modes::MOUSE_MOTION; + + terminal.mouse_move( + &MouseMoveEvent { + position: point(px(80.0), px(10.0)), + pressed_button: None, + modifiers: Modifiers::secondary_key(), + }, + MouseInputMode::ReportToTerminal, + cx, + ); + + assert!( + !any_event_matches!(terminal, InternalEvent::FindHyperlink(_, _)), + "with the setting disabled, ctrl+hover must not look up links in mouse mode" + ); + }); + } + #[gpui::test] async fn test_hyperlink_ctrl_click_drag_outside_bounds(cx: &mut TestAppContext) { let terminal = init_terminal_test(