Skip to content

feat(par): make first-line-indent foldable - #7123

Closed
JuanHPassos wants to merge 8 commits into
typst:mainfrom
JuanHPassos:feat/7052/decouple-indent-properties
Closed

JuanHPassos wants to merge 8 commits into
typst:mainfrom
JuanHPassos:feat/7052/decouple-indent-properties

Conversation

@JuanHPassos

Copy link
Copy Markdown
Contributor

Closes #7052

Summary

This PR makes the par.first-line-indent property foldable, allowing for partial updates.

Currently, first-line-indent is treated as a single unit. If a template or a set rule defines a full value like (amount: 2em, all: false), a user cannot update just one key without overriding the entire struct. For example, applying set par(first-line-indent: (all: true)) would reset the amount to its default value, which is an undesirable side effect.

With this change, partial dictionaries are merged with the existing style. The same set rule will now correctly preserve the amount, resulting in (amount: 2em, all: true). This makes style composition more intuitive and powerful, consistent with other foldable properties in Typst.

Implementation

The folding behavior was implemented idiomatically using the framework's built-in mechanisms:

  • The first_line_indent field in ParElem is now marked with the #[fold] attribute.
  • The FirstLineIndent struct implements the styles::Fold trait to define how new values are merged with existing ones.
  • The cast! macro for FirstLineIndent was adjusted to correctly handle partial dictionaries by supplying default values for missing keys, which is necessary for the fold logic to work.

Testing

The changes were verified with a test .typ file that covers the following scenarios:

  • Main Use Case: Setting all: true correctly preserves a previously set amount.
  • Reverse Case: Setting a new amount correctly preserves a previously set all: true.
  • Full Override: Setting both amount and all at the same time correctly overrides the previous style.
  • Shorthand: The length shorthand (e.g., 10pt) continues to work as expected.

All tests passed, and the visual output in the generated PDF matches the expected behavior.


Checklist

  • I have read the contributing guidelines.
  • I have documented my changes.
  • I have added tests that prove my fix is effective or that my feature works.

@JuanHPassos

Copy link
Copy Markdown
Contributor Author

Hi @MDLC01 , I think I’m done! Could you review my PR?

@MDLC01

MDLC01 commented Oct 18, 2025

Copy link
Copy Markdown
Collaborator

The team is busy right now with the release of Typst 0.14.0, but they will likely review your PR after the new version is released.

@laurmaedje laurmaedje added layout Related to the layout category, which is about composing, positioning, etc. interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. styling About set and show rules or style properties labels Oct 27, 2025
@laurmaedje

Copy link
Copy Markdown
Member

Given that

  • the PR description talks about testing without there being a single test
  • the PR description reading a lot like AI
  • the PR not being correct in terms of implementation: The fields need to be optional for folding to have a chance to work correctly. Comparing against the defaults is not sufficient.

I'll close this.

@laurmaedje laurmaedje closed this Nov 17, 2025
YDX-2147483647 pushed a commit to YDX-2147483647/typst that referenced this pull request Jan 23, 2026
feat(par): make first-line-indent foldable

style: apply rustfmt
YDX-2147483647 pushed a commit to YDX-2147483647/typst that referenced this pull request Jan 27, 2026
feat(par): make first-line-indent foldable

style: apply rustfmt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

interface PRs that add to or change Typst's user-facing interface as opposed to internals or docs changes. layout Related to the layout category, which is about composing, positioning, etc. styling About set and show rules or style properties

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make par.first-line-indent fold

3 participants