Hyperlinks: test that Ctrl+click beside the link text still extends the selection (#1198)

This commit is contained in:
xc4pr
2026-10-23 02:23:37 +02:00
parent d046ba6aa7
commit 60776ff4de
+18 -3
View File
@@ -26,16 +26,20 @@ fn harness() -> Harness {
h
}
fn left_of_cell(h: &Harness, cell: &str) -> Pos2 {
fn at_fraction(h: &Harness, cell: &str, fraction: f32) -> Pos2 {
let app = h.state();
let sheet = app.session.active().unwrap().wb.active().unwrap();
let geo = Geo::new(sheet, app.grid.rect.unwrap(), app.view().scroll);
let r = geo.cell_rect(sheet, CellRef::parse(cell).unwrap());
egui::pos2(r.left() + r.width() * 0.3, r.center().y)
egui::pos2(r.left() + r.width() * fraction, r.center().y)
}
fn click(h: &mut Harness, cell: &str, modifiers: Modifiers) {
let pos = left_of_cell(h, cell);
click_at(h, cell, 0.3, modifiers);
}
fn click_at(h: &mut Harness, cell: &str, fraction: f32, modifiers: Modifiers) {
let pos = at_fraction(h, cell, fraction);
h.input_mut().events.push(Event::ModifiersChanged(modifiers));
h.input_mut().events.extend([
Event::PointerMoved(pos),
@@ -68,3 +72,14 @@ fn plain_click_still_follows() {
click(&mut h, "B4", Modifiers::NONE);
assert_eq!(h.state().session.active().unwrap().selection.active.a1(), "F9");
}
#[test]
fn ctrl_click_beside_the_link_text_still_extends_the_selection() {
let mut h = harness();
click_at(&mut h, "B2", 0.9, Modifiers::NONE);
click_at(&mut h, "B4", 0.9, Modifiers::COMMAND);
let d = h.state().session.active().unwrap();
let ranges: Vec<String> = d.selection.ranges.iter().map(|r| r.a1()).collect();
assert_eq!(ranges, ["B2", "B4"], "the hyperlink cell joins the selection");
assert!(h.state().dialog.is_none(), "no link was followed");
}