From 61f9f7389f2ff77b4ce35ef050cf5942c2dd169b Mon Sep 17 00:00:00 2001 From: Matt Fellenz Date: Tue, 11 Mar 2025 11:55:34 +0100 Subject: [PATCH] Address review --- crates/typst-ide/src/jump.rs | 16 ++++++++++++++-- crates/typst-library/src/visualize/curve.rs | 8 ++++---- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index c03f83221..8e55bbd17 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -59,7 +59,13 @@ pub fn jump_from_click( continue; } } - let pos = pos.transform_inf(group.transform.invert().unwrap()); + // Realistic transforms should always be invertible. + // An example of one that isn't is a scale of 0, which would + // not be clickable anyway. + let Some(inv_transform) = group.transform.invert() else { + continue; + }; + let pos = pos.transform_inf(inv_transform); if let Some(span) = jump_from_click(world, document, &group.frame, pos) { return Some(span); } @@ -292,7 +298,8 @@ mod tests { cursor(45), ); test_click( - "#box(width: 10pt, height: 10pt, clip: true, scale(x: 300%, y: 300%, origin: top + left, rect(width: 10pt, height: 10pt)))", + "#box(width: 10pt, height: 10pt, clip: true, scale(x: 300%, y: 300%, \ + origin: top + left, rect(width: 10pt, height: 10pt)))", point(20.0, 20.0) + margin, None, ); @@ -306,6 +313,11 @@ mod tests { point(20.0, 20.0) + margin, None, ); + test_click( + "#rotate(90deg, origin: bottom + left)[hello world]", + point(5.0, 15.0) + margin, + cursor(40), + ); } #[test] diff --git a/crates/typst-library/src/visualize/curve.rs b/crates/typst-library/src/visualize/curve.rs index f797ff852..c7991817e 100644 --- a/crates/typst-library/src/visualize/curve.rs +++ b/crates/typst-library/src/visualize/curve.rs @@ -531,10 +531,6 @@ impl Curve { } } -fn point_to_kurbo(point: Point) -> kurbo::Point { - kurbo::Point::new(point.x.to_raw(), point.y.to_raw()) -} - impl Curve { fn to_kurbo(&self) -> kurbo::BezPath { use kurbo::{BezPath, PathEl}; @@ -557,3 +553,7 @@ impl Curve { kurbo::Shape::contains(&self.to_kurbo(), point_to_kurbo(needle)) } } + +fn point_to_kurbo(point: Point) -> kurbo::Point { + kurbo::Point::new(point.x.to_raw(), point.y.to_raw()) +}