Repository navigation
Padding shorthands show in the spacing box, and padding edits stay compact - #36
Merged
flowtricks merged 1 commit intoOct 13, 2026
Conversation
The spacing box has one field per side, so `padding: 1rem 2rem` reached none of them while still applying on the page: the box read as empty and the shorthand sat in Custom properties. Dragging a side of such a rule appended a longhand beside the shorthand it overrode, and four drags left five declarations. Reading: the resolver projects `padding`, `padding-block`, `padding-inline` and `margin` (one to four values) onto the sides they set, so the box shows them and an edit goes to the rule that holds the shorthand. The shorthand stays a property of its own and is still edited and cleared whole; reading never rewrites the source. Within a rule a later declaration wins unless an earlier one is `!important` and it is not, which the per-rule fold did not account for. Writing: a committed padding edit rewrites the rule's own padding in its shortest form, where its first padding declaration stood: `padding` when the four sides agree, else `padding-block` / `padding-inline` for each pair that agrees, else the sides. Only what the rule declares is compacted. A reset (Alt-click) of a side grouped into a shorthand splits it and keeps the other sides. Two cases are left as written on purpose. A multi-side value holding a var() or env() may substitute several lengths, so it is neither split nor compacted until every side overrides it. And a var() side is never grouped, since the shorthand it would make is one the next edit could not split again: the result would depend on the order of the edits. Margin is read only: a margin edit still appends a longhand. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The problem
The spacing box has one field per side, so a rule written
padding: 1rem 2remfilled none of them: the box read as empty while the padding applied on the page, and the shorthand only showed under Custom properties.Dragging a side of such a rule then appended a longhand beside the shorthand it overrode. Four drags left five declarations.
The change
Reading. The resolver projects
padding,padding-block,padding-inlineandmargin(one to four values) onto the sides they set. The box shows them, and an edit goes to the rule that holds the shorthand. The shorthand stays a property of its own, still edited and cleared whole under Custom properties. Reading never rewrites the source.Writing. A committed padding edit rewrites the rule's own padding in its shortest form, where its first padding declaration stood:
paddingwhen the four sides agree,padding-block/padding-inlinefor each pair that agrees,Only what the rule declares is compacted. Alt-click on a side grouped into a shorthand splits it and keeps the other sides.
The new module is
src/features/style/model/spacingShorthand.ts. It is wired intoresolved.ts(reading), and intocssRegions.tsanduseEditorRuleEdits.ts(writing).Choices worth a look
var()is left as written. A multi-side value holding avar()orenv()may substitute several lengths, so it is neither split nor compacted until every side overrides it. Avar()side is never grouped either: the shorthand it would make is one the next edit could not split again, so the result would depend on the order of the edits.padding-block+padding-inline, notpadding: a b. Sides are physical, as the box and the canvas bands already are.!importantinside a rule. A later declaration now wins unless an earlier one is!importantand it is not. The per-rule fold took the last declaration regardless.Tests
test/renderer/style/spacingShorthand.test.js: 16 cases on the model, through the real parser, cascade and resolver. They cover the values the box cannot read side by side,!important, queries, and the assertion on a non-padding property.test/renderer/style/spacingShorthandPanel.test.js: the realEmbedEditorin jsdom, with Shift, Alt, plain and reset drags, checked against the CSS written. It fails without the change.npm run check:changedpasses.🤖 Generated with Claude Code