mirror of
https://github.com/typst/typst
synced 2025-05-19 11:35:27 +08:00
Reduce trigger region of closure tooltip
This commit is contained in:
parent
9c29dbf84f
commit
265b37d12d
@ -5,7 +5,7 @@ use if_chain::if_chain;
|
|||||||
use typst::doc::Frame;
|
use typst::doc::Frame;
|
||||||
use typst::eval::{CapturesVisitor, CastInfo, Repr, Tracer, Value};
|
use typst::eval::{CapturesVisitor, CastInfo, Repr, Tracer, Value};
|
||||||
use typst::geom::{round_2, Length, Numeric};
|
use typst::geom::{round_2, Length, Numeric};
|
||||||
use typst::syntax::ast::{self, AstNode};
|
use typst::syntax::ast;
|
||||||
use typst::syntax::{LinkedNode, Source, SyntaxKind};
|
use typst::syntax::{LinkedNode, Source, SyntaxKind};
|
||||||
use typst::util::{pretty_comma_list, separated_list};
|
use typst::util::{pretty_comma_list, separated_list};
|
||||||
use typst::World;
|
use typst::World;
|
||||||
@ -103,16 +103,21 @@ fn expr_tooltip(world: &dyn World, leaf: &LinkedNode) -> Option<Tooltip> {
|
|||||||
|
|
||||||
/// Tooltip for a hovered closure.
|
/// Tooltip for a hovered closure.
|
||||||
fn closure_tooltip(leaf: &LinkedNode) -> Option<Tooltip> {
|
fn closure_tooltip(leaf: &LinkedNode) -> Option<Tooltip> {
|
||||||
// Find the closure to analyze.
|
// Only show this tooltip when hovering over the equals sign or arrow of
|
||||||
let mut ancestor = leaf;
|
// the closure. Showing it across the whole subtree is too noisy.
|
||||||
while !ancestor.is::<ast::Closure>() {
|
if !matches!(leaf.kind(), SyntaxKind::Eq | SyntaxKind::Arrow) {
|
||||||
ancestor = ancestor.parent()?;
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the closure to analyze.
|
||||||
|
let parent = leaf.parent()?;
|
||||||
|
if parent.kind() != SyntaxKind::Closure {
|
||||||
|
return None;
|
||||||
}
|
}
|
||||||
let closure = ancestor.cast::<ast::Closure>()?.to_untyped();
|
|
||||||
|
|
||||||
// Analyze the closure's captures.
|
// Analyze the closure's captures.
|
||||||
let mut visitor = CapturesVisitor::new(None);
|
let mut visitor = CapturesVisitor::new(None);
|
||||||
visitor.visit(closure);
|
visitor.visit(parent);
|
||||||
|
|
||||||
let captures = visitor.finish();
|
let captures = visitor.finish();
|
||||||
let mut names: Vec<_> =
|
let mut names: Vec<_> =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user