Repository navigation
Make par.first-line-indent foldable - #7747
Conversation
feat(par): make first-line-indent foldable style: apply rustfmt
e13e651 to
38fbd7d
Compare
laurmaedje
left a comment
There was a problem hiding this comment.
There is a slight issue with auto being accepted. This should not be the case.
Implementation-wise, an alternative would have been to have just one struct, but have accessor methods on FirstLineIndent that basically perform the unwrap or default action internally, then having the defaults specified in constants that are used there and in an impl Default for FirstLineIndent.
I'm not sure which is better. Folding is unfortunately a mess. I wanted to point to the Fold impl for Augment, but it's actually wrong... there, a hline config overwrites an existing vline and vice versa.
480846d to
f6bf4db
Compare
|
I reorganized it and replaced "FixedFirstLineIndent" with accessors. It's cleaner now. |
| "amount" => indent.amount(), | ||
| "all" => indent.all(), |
There was a problem hiding this comment.
These properties should not be included in the dictionary if they are None, rather than then using the default, since the None represents the strongly-typed version of an absent key.
There was a problem hiding this comment.
As explained in the PR description, I want context par.first-line-indent to have defaults filled.
impl From<FirstLineIndent> for Dict was added in #5768, and it looks like the only usage was in cast!, so I implemented the logic here.
cast! {
FirstLineIndent,
self => Value::Dict(self.into()),I've just removed impl From<FirstLineIndent> for Dict. How about now?
There was a problem hiding this comment.
As explained in the PR description, I want context par.first-line-indent to have defaults filled.
That shouldn't be an issue, since context par.first-line-indent will observe the folded value and since the default is initialized with Some(_) fields, they cannot be None after folding in practice. My comment was only about having the correct semantical behavior of the code. The code for folding across the code base is already a bit all over the place and if we give up on the semantics, I fear at some point nobody will understand it anymore, including me.
If you reintroduce the impl From<FirstLineIndent> for Dict with the None handling, I think it should all work as you expect.
At some point, I might create some additional infrastructure to make foldable properties less confusing to implement.
There was a problem hiding this comment.
That shouldn't be an issue
Indeed! I was misled by my initial implementation. (In that version, the struct FirstLineIndent and the parameter par.first-line-indent have different default values. Therefore, that didn't work.)
Now updated.
create some additional infrastructure to make foldable properties less confusing to implement
I'm looking forward to it. It did take me some time to figure out the relationship between Fold and AlternativeFold, what should be stored if a key is not given, …
There was a problem hiding this comment.
The diff now is unfortunately still not quite what I meant. 🫠
Now, None values would be turned into Typst none values in the dictionary rather than being absent.
What I meant is that they would not be inserted at all, like in IntoValue for Sides<Option<T>>.
There was a problem hiding this comment.
Oh, I guess this version would match what you meant…
a43d5c8 to
74f6350
Compare
|
Thanks! |
Co-authored-by: JuanHPassos <[email protected]>
Co-authored-by: JuanHPassos <[email protected]>
In Typst 0.14, the following typst code emits an error (Dictionary does not contain key "amount").
In this PR, it enables
allwithout affecting theamount. It would be helpful for templates and also handy for one-off toggling.Resolves #7052
Continues #7123 (which was rejected because AI didn't fully implement it)
Further details
Values from
contextGitHub search shows that people are assuming
type(par.first-line-indent.amount) == length. (#3206 (comment) has a concrete example.)Therefore, this PR keeps this assumption.
Note that this behaviour is not consistent with
grid.stroke, which is also both foldable and smart.Outdated content
Repeated code
The ad hoc
takefunction thatcast!Dict -> FirstLineIndentis copied fromstroke.rs.I'm not sure if it's worth merging the two functions.
typst/crates/typst-library/src/visualize/stroke.rs
Lines 379 to 388 in 7cfde04