terminal: Highlight links on ctrl/cmd-hover in mouse mode
When the running app had mouse reporting on, moving the pointer over a link with ctrl/cmd held never underlined it, while pressing the modifier with the pointer already on the link did. `mouse_move` only scheduled the hyperlink lookup outside of mouse mode, but the modifier change and grid refresh paths don't check it, and ctrl/cmd-click already opens links in mouse mode through `open_links_in_mouse_mode`. Also look up the hovered link in mouse mode when that setting is on, after the motion has been reported to the app. Closes #64102
This commit is contained in:
1 parent
8acb6f4d72
commit
e3da47c875
1 file changed
+71
@@ -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 {
|
} else {
|
||||||
self.schedule_find_hyperlink(e.modifiers, e.position, cx);
|
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]
|
#[gpui::test]
|
||||||
async fn test_hyperlink_ctrl_click_drag_outside_bounds(cx: &mut TestAppContext) {
|
async fn test_hyperlink_ctrl_click_drag_outside_bounds(cx: &mut TestAppContext) {
|
||||||
let terminal = init_terminal_test(
|
let terminal = init_terminal_test(
|
||||||
|
|||||||
Reference in new issue
Block a user