Fix ctrl hyperlink highlighting when using splits, fixes #688

This commit is contained in:
Jeremy Soller 2026-01-12 11:04:12 -07:00 committed by Ashley Wulber
parent dae3e28ff4
commit 55b3cb93b3

View file

@ -1004,9 +1004,9 @@ where
{ {
//Might need to update the url regex highlight, //Might need to update the url regex highlight,
//so we need to calculate the mouse position //so we need to calculate the mouse position
let location = if let Some(p) = cursor_position.position() { let location = if let Some(p) = cursor_position.position_in(layout.bounds()) {
let x = (p.x - layout.bounds().x) - self.padding.left; let x = p.x - self.padding.left;
let y = (p.y - layout.bounds().y) - self.padding.top; let y = p.y - self.padding.top;
//TODO: better calculation of position //TODO: better calculation of position
let col = x / terminal.size().cell_width; let col = x / terminal.size().cell_width;
let row = y / terminal.size().cell_height; let row = y / terminal.size().cell_height;
@ -1150,8 +1150,11 @@ where
if let Some(ref mut selection) = term.selection { if let Some(ref mut selection) = term.selection {
selection.update(location, side); selection.update(location, side);
} else { } else {
term.selection = term.selection = Some(Selection::new(
Some(Selection::new(SelectionType::Simple, location, side)); SelectionType::Simple,
location,
side,
));
} }
} else { } else {
let selection = match click_kind { let selection = match click_kind {
@ -1312,29 +1315,38 @@ where
self.mouse_inside_boundary = Some(mouse_is_inside); self.mouse_inside_boundary = Some(mouse_is_inside);
} }
} }
if let Some(p) = cursor_position.position() { if let Some(p_global) = cursor_position.position() {
let bounds = layout.bounds(); let bounds = layout.bounds();
let x = (p.x - bounds.x) - self.padding.left; let col_row_opt = if let Some(p) = cursor_position.position_in(bounds) {
let y = (p.y - bounds.y) - self.padding.top; let x = p.x - self.padding.left;
//TODO: better calculation of position let y = p.y - self.padding.top;
let col = x / terminal.size().cell_width; //TODO: better calculation of position
let row = y / terminal.size().cell_height; let col = x / terminal.size().cell_width;
let location = terminal let row = y / terminal.size().cell_height;
.viewport_to_point(TermPoint::new(row as usize, TermColumn(col as usize))); let location = terminal.viewport_to_point(TermPoint::new(
update_active_regex_match( row as usize,
&mut terminal, TermColumn(col as usize),
Some(location), ));
Some(&state.modifiers), update_active_regex_match(
); &mut terminal,
Some(location),
Some(&state.modifiers),
);
Some((col, row))
} else {
None
};
if is_mouse_mode { if is_mouse_mode {
terminal.report_mouse(event, &state.modifiers, col as u32, row as u32); if let Some((col, row)) = col_row_opt {
terminal.report_mouse(event, &state.modifiers, col as u32, row as u32);
}
} else { } else {
let handled_buffer_drag = update_buffer_drag( let handled_buffer_drag = update_buffer_drag(
state, state,
&mut terminal, &mut terminal,
buffer_size, buffer_size,
p, p_global,
bounds, bounds,
self.padding, self.padding,
0.0, 0.0,
@ -1346,6 +1358,7 @@ where
start_scroll, start_scroll,
}) = state.dragging.as_mut() }) = state.dragging.as_mut()
{ {
let y = p_global.y - bounds.y - self.padding.top;
let start_y = *start_y; let start_y = *start_y;
let start_scroll = *start_scroll; let start_scroll = *start_scroll;
let scroll_offset = terminal.with_buffer(|buffer| { let scroll_offset = terminal.with_buffer(|buffer| {
@ -1360,9 +1373,9 @@ where
state.autoscroll.stop(); state.autoscroll.stop();
} else { } else {
if state.autoscroll.is_active() { if state.autoscroll.is_active() {
state.autoscroll.update_pointer(p); state.autoscroll.update_pointer(p_global);
} else { } else {
state.autoscroll.start(p); state.autoscroll.start(p_global);
} }
shell.request_redraw(RedrawRequest::NextFrame); shell.request_redraw(RedrawRequest::NextFrame);
} }
@ -1375,8 +1388,8 @@ where
Event::Mouse(MouseEvent::WheelScrolled { delta }) => { Event::Mouse(MouseEvent::WheelScrolled { delta }) => {
if let Some(p) = cursor_position.position_in(layout.bounds()) { if let Some(p) = cursor_position.position_in(layout.bounds()) {
if is_mouse_mode { if is_mouse_mode {
let x = (p.x - layout.bounds().x) - self.padding.left; let x = p.x - self.padding.left;
let y = (p.y - layout.bounds().y) - self.padding.top; let y = p.y - self.padding.top;
//TODO: better calculation of position //TODO: better calculation of position
let col = x / terminal.size().cell_width; let col = x / terminal.size().cell_width;
let row = y / terminal.size().cell_height; let row = y / terminal.size().cell_height;
@ -1477,12 +1490,17 @@ fn osc8_hyperlink_at(
location: TermPoint, location: TermPoint,
) -> Option<alacritty_terminal::term::cell::Hyperlink> { ) -> Option<alacritty_terminal::term::cell::Hyperlink> {
let term = terminal.term.lock(); let term = terminal.term.lock();
if location.line >= term.screen_lines() || location.column.0 >= term.columns() {
return None;
}
let grid = term.grid(); let grid = term.grid();
let cell = &grid[location]; let cell = &grid[location];
if let Some(link) = cell.hyperlink() { if let Some(link) = cell.hyperlink() {
return Some(link); return Some(link);
} }
if cell.flags.intersects(Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER) if cell
.flags
.intersects(Flags::WIDE_CHAR_SPACER | Flags::LEADING_WIDE_CHAR_SPACER)
&& location.column.0 > 0 && location.column.0 > 0
{ {
let left = TermPoint::new(location.line, TermColumn(location.column.0 - 1)); let left = TermPoint::new(location.line, TermColumn(location.column.0 - 1));