Compare commits

...

3 Commits

Author SHA1 Message Date
Andrew Voynov
e632bffc2e
Document how to escape lr delimiter auto-scaling (#6410)
Co-authored-by: Laurenz <laurmaedje@gmail.com>
2025-06-09 16:34:39 +00:00
Andrew Voynov
2a3746c51d
Update docs for gradient.repeat (#6385) 2025-06-09 14:25:33 +00:00
cAttte
df4c08f852
Autocomplete fixes for math mode (#6415) 2025-06-09 14:16:47 +00:00
4 changed files with 37 additions and 4 deletions

View File

@ -298,13 +298,20 @@ fn complete_math(ctx: &mut CompletionContext) -> bool {
return false; return false;
} }
// Start of an interpolated identifier: "#|". // Start of an interpolated identifier: "$#|$".
if ctx.leaf.kind() == SyntaxKind::Hash { if ctx.leaf.kind() == SyntaxKind::Hash {
ctx.from = ctx.cursor; ctx.from = ctx.cursor;
code_completions(ctx, true); code_completions(ctx, true);
return true; return true;
} }
// Behind existing interpolated identifier: "$#pa|$".
if ctx.leaf.kind() == SyntaxKind::Ident {
ctx.from = ctx.leaf.offset();
code_completions(ctx, true);
return true;
}
// Behind existing atom or identifier: "$a|$" or "$abc|$". // Behind existing atom or identifier: "$a|$" or "$abc|$".
if matches!( if matches!(
ctx.leaf.kind(), ctx.leaf.kind(),
@ -1666,6 +1673,13 @@ mod tests {
test("#{() .a}", -2).must_include(["at", "any", "all"]); test("#{() .a}", -2).must_include(["at", "any", "all"]);
} }
/// Test that autocomplete in math uses the correct global scope.
#[test]
fn test_autocomplete_math_scope() {
test("$#col$", -2).must_include(["colbreak"]).must_exclude(["colon"]);
test("$col$", -2).must_include(["colon"]).must_exclude(["colbreak"]);
}
/// Test that the `before_window` doesn't slice into invalid byte /// Test that the `before_window` doesn't slice into invalid byte
/// boundaries. /// boundaries.
#[test] #[test]

View File

@ -114,7 +114,9 @@ pub fn globals<'a>(world: &'a dyn IdeWorld, leaf: &LinkedNode) -> &'a Scope {
| Some(SyntaxKind::Math) | Some(SyntaxKind::Math)
| Some(SyntaxKind::MathFrac) | Some(SyntaxKind::MathFrac)
| Some(SyntaxKind::MathAttach) | Some(SyntaxKind::MathAttach)
); ) && leaf
.prev_leaf()
.is_none_or(|prev| !matches!(prev.kind(), SyntaxKind::Hash));
let library = world.library(); let library = world.library();
if in_math { if in_math {

View File

@ -549,7 +549,7 @@ impl Gradient {
} }
/// Repeats this gradient a given number of times, optionally mirroring it /// Repeats this gradient a given number of times, optionally mirroring it
/// at each repetition. /// at every second repetition.
/// ///
/// ```example /// ```example
/// #circle( /// #circle(
@ -564,7 +564,17 @@ impl Gradient {
&self, &self,
/// The number of times to repeat the gradient. /// The number of times to repeat the gradient.
repetitions: Spanned<usize>, repetitions: Spanned<usize>,
/// Whether to mirror the gradient at each repetition. /// Whether to mirror the gradient at every second repetition, i.e.,
/// the first instance (and all odd ones) stays unchanged.
///
/// ```example
/// #circle(
/// radius: 40pt,
/// fill: gradient
/// .conic(green, black)
/// .repeat(2, mirror: true)
/// )
/// ```
#[named] #[named]
#[default(false)] #[default(false)]
mirror: bool, mirror: bool,

View File

@ -112,11 +112,18 @@
a few more functions that create delimiter pairings for absolute, ceiled, a few more functions that create delimiter pairings for absolute, ceiled,
and floored values as well as norms. and floored values as well as norms.
To prevent a delimiter from being matched by Typst, and thus auto-scaled,
escape it with a backslash. To instead disable auto-scaling completely, use
`{set math.lr(size: 1em)}`.
# Example # Example
```example ```example
$ [a, b/2] $ $ [a, b/2] $
$ lr(]sum_(x=1)^n], size: #50%) x $ $ lr(]sum_(x=1)^n], size: #50%) x $
$ abs((x + y) / 2) $ $ abs((x + y) / 2) $
$ \{ (x / y) \} $
#set math.lr(size: 1em)
$ { (a / b), a, b in (0; 1/2] } $
``` ```
- name: calc - name: calc