diff options
| author | Laurenz <laurmaedje@gmail.com> | 2023-03-15 12:33:38 +0100 |
|---|---|---|
| committer | Laurenz <laurmaedje@gmail.com> | 2023-03-15 12:33:38 +0100 |
| commit | ecb5543985cc0788d9c01e8c2e28d8ca6d8e19b6 (patch) | |
| tree | fcd6dfaad54d4076ee6d767ceb5f388b3c84225b /src/ide | |
| parent | 85678118086b29b3820813411cf382fa283b39f0 (diff) | |
Node links
Diffstat (limited to 'src/ide')
| -rw-r--r-- | src/ide/analyze.rs | 5 | ||||
| -rw-r--r-- | src/ide/jump.rs | 22 |
2 files changed, 20 insertions, 7 deletions
diff --git a/src/ide/analyze.rs b/src/ide/analyze.rs index 7338ba57..ed868e53 100644 --- a/src/ide/analyze.rs +++ b/src/ide/analyze.rs @@ -74,12 +74,11 @@ pub fn analyze_labels( frames: &[Frame], ) -> (Vec<(Label, Option<EcoString>)>, usize) { let mut output = vec![]; - let mut introspector = Introspector::new(); + let introspector = Introspector::new(frames); let items = &world.library().items; - introspector.update(frames); // Labels in the document. - for node in introspector.iter() { + for node in introspector.nodes() { let Some(label) = node.label() else { continue }; let details = node .field("caption") diff --git a/src/ide/jump.rs b/src/ide/jump.rs index 033d0f7f..95f2fa02 100644 --- a/src/ide/jump.rs +++ b/src/ide/jump.rs @@ -2,6 +2,7 @@ use std::num::NonZeroUsize; use crate::doc::{Destination, Element, Frame, Location, Meta}; use crate::geom::{Point, Size}; +use crate::model::Introspector; use crate::syntax::{LinkedNode, Source, SourceId, Span, SyntaxKind}; use crate::World; @@ -15,11 +16,19 @@ pub enum Jump { } /// Determine where to jump to based on a click in a frame. -pub fn jump_from_click(world: &dyn World, frame: &Frame, click: Point) -> Option<Jump> { +pub fn jump_from_click( + world: &dyn World, + frames: &[Frame], + frame: &Frame, + click: Point, +) -> Option<Jump> { + let mut introspector = None; + for (mut pos, element) in frame.elements() { if let Element::Group(group) = element { // TODO: Handle transformation. - if let Some(span) = jump_from_click(world, &group.frame, click - pos) { + if let Some(span) = jump_from_click(world, frames, &group.frame, click - pos) + { return Some(span); } } @@ -55,9 +64,14 @@ pub fn jump_from_click(world: &dyn World, frame: &Frame, click: Point) -> Option } } - if let Element::Meta(Meta::Link(dest), size) = element { + if let Element::Meta(Meta::Link(link), size) = element { if is_in_rect(pos, *size, click) { - return Some(Jump::Dest(dest.clone())); + let dest = link.resolve(|| { + introspector.get_or_insert_with(|| Introspector::new(frames)) + }); + + let Some(dest) = dest else { continue }; + return Some(Jump::Dest(dest)); } } } |
