diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-06-17 14:15:24 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-17 12:15:24 +0000 |
| commit | a2c980715958bc3fd71e1f0a5975fea3f5b63b85 (patch) | |
| tree | 66794a09bf59069217a21443f88778bd77fd12d2 /crates/typst-ide/src | |
| parent | 0d93ccd4bfc814534c106d3f78eef16b06b3cc70 (diff) | |
Fix backlinks (#4409)
Diffstat (limited to 'crates/typst-ide/src')
| -rw-r--r-- | crates/typst-ide/src/jump.rs | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index f632d933..a97e5a0a 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -168,6 +168,15 @@ fn is_in_rect(pos: Point, size: Size, click: Point) -> bool { #[cfg(test)] mod tests { + //! This can be used in a normal test to determine positions: + //! ``` + //! #set page(background: place( + //! dx: 10pt, + //! dy: 10pt, + //! square(size: 2pt, fill: red), + //! )) + //! ``` + use std::num::NonZeroUsize; use typst::layout::{Abs, Point, Position}; @@ -200,7 +209,16 @@ mod tests { fn test_click(text: &str, click: Point, expected: Option<Jump>) { let world = TestWorld::new(text); let doc = typst::compile(&world).output.unwrap(); - assert_eq!(jump_from_click(&world, &doc, &doc.pages[0].frame, click), expected); + let jump = jump_from_click(&world, &doc, &doc.pages[0].frame, click); + if let (Some(Jump::Position(pos)), Some(Jump::Position(expected))) = + (&jump, &expected) + { + assert_eq!(pos.page, expected.page); + assert_approx_eq!(pos.point.x, expected.point.x); + assert_approx_eq!(pos.point.y, expected.point.y); + } else { + assert_eq!(jump, expected); + } } #[track_caller] @@ -240,4 +258,10 @@ mod tests { test_cursor(s, 12, None); test_cursor(s, 14, pos(1, 37.55, 16.58)); } + + #[test] + fn test_backlink() { + let s = "#footnote[Hi]"; + test_click(s, point(10.0, 10.0), pos(1, 18.5, 37.1).map(Jump::Position)); + } } |
