diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-11-11 15:11:44 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2024-11-13 10:21:40 +0100 |
| commit | 525154a730dfdb224fe2ced3dae0cfb33114fafa (patch) | |
| tree | c81f490cb6b2091146d787fdc044f7be530d8181 /crates/typst-ide | |
| parent | 5625914872b2824388ce65f3fb184d913f29cbff (diff) | |
Add support for raw range spans
Diffstat (limited to 'crates/typst-ide')
| -rw-r--r-- | crates/typst-ide/src/jump.rs | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index 5d270f04..2dd5cf61 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -4,14 +4,15 @@ use typst::layout::{Frame, FrameItem, Point, Position, Size}; use typst::model::{Destination, Document, Url}; use typst::syntax::{FileId, LinkedNode, Side, Source, Span, SyntaxKind}; use typst::visualize::Geometry; +use typst::WorldExt; use crate::IdeWorld; /// Where to [jump](jump_from_click) to. #[derive(Debug, Clone, Eq, PartialEq)] pub enum Jump { - /// Jump to a position in a source file. - Source(FileId, usize), + /// Jump to a position in a file. + File(FileId, usize), /// Jump to an external URL. Url(Url), /// Jump to a point on a page. @@ -21,9 +22,8 @@ pub enum Jump { impl Jump { fn from_span(world: &dyn IdeWorld, span: Span) -> Option<Self> { let id = span.id()?; - let source = world.source(id).ok()?; - let node = source.find(span)?; - Some(Self::Source(id, node.offset())) + let offset = world.range(span)?.start; + Some(Self::File(id, offset)) } } @@ -83,7 +83,7 @@ pub fn jump_from_click( } else { node.offset() }; - return Some(Jump::Source(source.id(), pos)); + return Some(Jump::File(source.id(), pos)); } pos.x += width; @@ -194,7 +194,7 @@ mod tests { } fn cursor(cursor: usize) -> Option<Jump> { - Some(Jump::Source(TestWorld::main_id(), cursor)) + Some(Jump::File(TestWorld::main_id(), cursor)) } fn pos(page: usize, x: f64, y: f64) -> Option<Position> { |
