Skip to content

fix: prevent wrap-text from merging lines before block elements#469

Open
Enter-tainer wants to merge 1 commit intomasterfrom
fix-468
Open

fix: prevent wrap-text from merging lines before block elements#469
Enter-tainer wants to merge 1 commit intomasterfrom
fix-468

Conversation

@Enter-tainer
Copy link
Collaborator

Summary

Fixes #468

When wrap-text is enabled, convert_markup_body_reflow() uses softlines between consecutive markup lines so the pretty printer can re-wrap them. However, it only checked the last node of the current line (should_break_after) to decide whether a hardline is needed, missing the case where the next line starts with a block element (ListItem, EnumItem, TermItem, Heading, or LineComment).

This caused nested list items and other block elements to be incorrectly flattened into the preceding line.

Changes

  • Add a symmetric check on the first node of the next line in the softline condition of convert_markup_body_reflow() (+4 lines in markup.rs)
  • Add test fixture list-nested-468.typ covering nested lists, enums, terms, headings, and content blocks
  • Add snapshots for 4 column widths (0, 40, 80, 120)

Test plan

  • New list-nested-468 tests: 10/10 passed (4 snapshot + 3 consistency + 3 convergence)
  • Full test suite: 2640 passed, 0 regressions (0 new .snap.new files)

🤖 Generated with Claude Code

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Enter-tainer, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a formatting bug in the wrap-text functionality where block elements were incorrectly merged with preceding lines. The core change involves refining the logic that determines softline insertion, ensuring that block elements consistently start on new lines as intended. This prevents unintended flattening of structured content, improving the reliability of text reflowing.

Highlights

  • Bug Fix: Resolved an issue where the wrap-text feature incorrectly merged lines before block elements (like list items, enums, terms, and headings), leading to flattened structures.
  • Code Logic Improvement: Enhanced the convert_markup_body_reflow() function in markup.rs by adding a symmetric check for the first node of the subsequent line, ensuring proper line breaks before block elements.
  • Test Coverage: Introduced a new test fixture (list-nested-468.typ) and corresponding snapshots for various column widths (0, 40, 80, 120) to specifically cover nested lists, enums, terms, headings, and content blocks, verifying the fix.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • crates/typstyle-core/src/pretty/markup.rs
    • Modified the convert_markup_body_reflow function to include a check for block elements at the start of the next line when deciding on softline insertion.
  • tests/fixtures/unit/markup/list-nested-468.typ
    • Added a new test fixture to cover scenarios involving nested lists, enums, terms, and headings, specifically targeting the wrap-text behavior.
  • tests/fixtures/unit/markup/snap/list-nested-468.typ-0.snap
    • Added a new snapshot for the list-nested-468.typ test case with a column width of 0.
  • tests/fixtures/unit/markup/snap/list-nested-468.typ-120.snap
    • Added a new snapshot for the list-nested-468.typ test case with a column width of 120.
  • tests/fixtures/unit/markup/snap/list-nested-468.typ-40.snap
    • Added a new snapshot for the list-nested-468.typ test case with a column width of 40.
  • tests/fixtures/unit/markup/snap/list-nested-468.typ-80.snap
    • Added a new snapshot for the list-nested-468.typ test case with a column width of 80.
Activity
  • The pull request was generated using Claude Code.
  • New list-nested-468 tests passed with 10/10, including 4 snapshot, 3 consistency, and 3 convergence tests.
  • The full test suite passed with 2640 tests and 0 regressions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request effectively fixes the issue where block-level elements (such as list items, headings, and line comments) were incorrectly merged with preceding text when the wrap-text configuration was enabled. By introducing a symmetric check on the first node of the next line, the reflow logic now correctly identifies when a hard break must be preserved to maintain the semantic structure of the Typst markup. The inclusion of a comprehensive test fixture covering various block elements and multiple column widths ensures the robustness of the fix.

@github-actions
Copy link

📊 Benchmark Performance Report

group                               base                                   pr
-----                               ----                                   --
pretty-ai-comprehensive-showcase    1.00   879.0±13.05µs        ? ?/sec    1.00   875.4±31.80µs        ? ?/sec
pretty-cetz-manual                  1.01   746.7±24.13µs        ? ?/sec    1.00   741.4±20.23µs        ? ?/sec
pretty-codly                        1.01  1748.7±12.65µs        ? ?/sec    1.00  1725.7±23.97µs        ? ?/sec
pretty-cpe                          1.01     11.8±0.10ms        ? ?/sec    1.00     11.8±0.07ms        ? ?/sec
pretty-deep-nested-args             1.00     16.8±0.29µs        ? ?/sec    1.01     17.0±0.11µs        ? ?/sec
pretty-fletcher-diagram             1.03   517.6±10.32µs        ? ?/sec    1.00    503.6±9.52µs        ? ?/sec
pretty-fletcher-draw                1.01  1238.8±20.16µs        ? ?/sec    1.00  1224.7±32.06µs        ? ?/sec
pretty-tablex                       1.01      3.3±0.01ms        ? ?/sec    1.00      3.3±0.02ms        ? ?/sec
pretty-touying-core                 1.01      2.1±0.01ms        ? ?/sec    1.00      2.1±0.02ms        ? ?/sec
pretty-touying-utils                1.01  1186.3±22.46µs        ? ?/sec    1.00  1174.7±16.39µs        ? ?/sec
pretty-undergraduate-math           1.02   859.2±11.89µs        ? ?/sec    1.00   839.5±13.84µs        ? ?/sec

📏 Binary Size Comparison

Metric Base PR Change
File Size 5.8 MB 5.8 MB 📈 +120 B (+0.0%)
Text Section 1.3 MB 1.3 MB 📈 +112 B (+0.01%)
📦 Detailed Crate Size Diff (cargo-bloat)

Note: Numbers above are a result of guesswork. They are not 100% correct and never will be.

@@ -1,8 +1,8 @@
 std                       394.6 kB
 clap_builder              323.0 kB
-typstyle_core             203.4 kB
+typstyle_core             203.5 kB
 clap_complete             126.4 kB
 typst_syntax              116.3 kB
 similar                   73.9 kB
 typstyle                  40.2 kB
 walkdir                   19.1 kB

Generated by GitHub Actions on 2026-02-16 11:33:59 UTC

When `wrap-text` is enabled, `convert_markup_body_reflow()` uses
softlines between consecutive markup lines so the pretty printer can
re-wrap them. However, it only checked the *last* node of the current
line (`should_break_after`) to decide whether a hardline is needed,
missing the case where the *next* line starts with a block element
(ListItem, EnumItem, TermItem, Heading, or LineComment).

This caused nested list items and other block elements to be incorrectly
flattened into the preceding line.

Add a symmetric check on the first node of the next line so that a
hardline is emitted before block elements, preserving the original
structure.

Closes #468

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: wrong formatting with nested lists and comments

1 participant