diff options
| author | Laurenz <laurmaedje@gmail.com> | 2024-11-13 12:01:38 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2024-11-13 12:03:47 +0100 |
| commit | 8dbbe68527e0855b87910fe367ef29f96a670408 (patch) | |
| tree | b80403da30012f623fe1d2d298dbd1def19f90a8 /crates/typst-ide/src/jump.rs | |
| parent | 737895d769188f6fc154523e67a9102bc24c872e (diff) | |
Backport IDE improvements0.12.0-with-extras
Diffstat (limited to 'crates/typst-ide/src/jump.rs')
| -rw-r--r-- | crates/typst-ide/src/jump.rs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/crates/typst-ide/src/jump.rs b/crates/typst-ide/src/jump.rs index e48db986..2dd5cf61 100644 --- a/crates/typst-ide/src/jump.rs +++ b/crates/typst-ide/src/jump.rs @@ -4,13 +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::World; +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. @@ -18,17 +20,16 @@ pub enum Jump { } impl Jump { - fn from_span(world: &dyn World, span: Span) -> Option<Self> { + 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)) } } /// Determine where to jump to based on a click in a frame. pub fn jump_from_click( - world: &dyn World, + world: &dyn IdeWorld, document: &Document, frame: &Frame, click: Point, @@ -82,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; @@ -193,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> { |
