Skip to content

editor: Include closing delimiter on same line when folding#50090

Merged
SomeoneToIgnore merged 9 commits intozed-industries:mainfrom
Dnreikronos:fix-indent-fold-closing-delimiter
Mar 24, 2026
Merged

editor: Include closing delimiter on same line when folding#50090
SomeoneToIgnore merged 9 commits intozed-industries:mainfrom
Dnreikronos:fix-indent-fold-closing-delimiter

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

CLOSES: #50002

When using indent-based folding (the default, document_folding_ranges = Off),
collapsed folds in brace-delimited languages displayed the closing delimiter on
a separate line:

fn b() {⋯
}

This extends the fold range in crease_for_buffer_row to include the trailing
newline and leading whitespace before a closing }, ), or ], producing
the expected single-line display:

fn b() {⋯}

Whitespace-sensitive languages like Python are unaffected — their terminating
lines don't start with a closing delimiter, so the existing behavior is
preserved.

Before you mark this PR as ready for review, make sure that you have:

  • Added a solid test coverage and/or screenshots from doing manual testing
  • Done a self-review taking into account security and performance aspects
  • Aligned any UI changes with the UI checklist

Screenshots:
Before:
image

After:
image

Release Notes:

  • Fixed indent-based code folding to display the closing delimiter (}, ), ]) on the same line as the fold placeholder instead of on a separate line (#50002).

  When using indent-based folding (the default), collapsed folds for
  brace-delimited languages showed the closing delimiter on a separate
  line (e.g.  / ). Now the fold range extends through the
  newline and leading whitespace before a closing , , or , so
  the collapsed display is a single line: .

  Whitespace-sensitive languages (Python) are unaffected because their
  terminating lines do not start with a closing delimiter.

  Closes zed-industries#50002
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Feb 25, 2026
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Dnreikronos commented Feb 25, 2026

Now it's handling HTML, CSS and JS files.

Screenshots:
image
image
image

Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Overall, it's not very clear why brackets have to be a part of all the heuristic code — if we can solve that and the rest of the comments, would be great.

@SomeoneToIgnore SomeoneToIgnore self-assigned this Mar 19, 2026
Address review feedback:
- Replace hardcoded `}`, `)`, `]` check with `scope.brackets()` from the
  language's bracket pair config. A `line_starts_with_closing_bracket`
  helper encapsulates the detection logic.
- Handle closing tags (`</`) separately since they aren't represented
  in bracket pair configs. Fall back to common delimiters when no
  language is set.
- Extract duplicated blank-line-skipping logic into a
`last_non_blank_row`
  closure.
- Remove the manual `chars_at` loop; use `line_indent_for_buffer_row`
  and `take_while` instead.
@github-actions github-actions bot added Size M and removed Size S labels Mar 23, 2026
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Thank you for the style fixes, we still use hardcoded values it seems, so things have not changed too much, globally.

Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Great, looks like the remaining questions are about the test code only.

…-industries#50090

rust_lang() now has BracketPairConfig ({}, [], (), <>, "") so fold tests
don't need rust_language_with_brackets_and_overrides() anymore. Split
test_fold_action into with-language and without-language variants. Raw
string and block comment fold tests also switched to rust_lang().
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Looking to the CI errors now

…ed-industries#50090)

The bracket pairs added to rust_lang() combined with
scope.brackets()-only detection now places closing delimiters on the
fold line. Update two assertions in folding_ranges tests to match the
new behavior.
Copy link
Copy Markdown
Contributor

@SomeoneToIgnore SomeoneToIgnore left a comment

Choose a reason for hiding this comment

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

Thank you!

@SomeoneToIgnore SomeoneToIgnore merged commit 72c1d97 into zed-industries:main Mar 24, 2026
31 checks passed
@Dnreikronos
Copy link
Copy Markdown
Contributor Author

Thank you!

Thank you for all the help and guidance!!

@nanyuantingfeng
Copy link
Copy Markdown

@Dnreikronos How can it be configured to display like this?

@Dnreikronos
Copy link
Copy Markdown
Contributor Author

@Dnreikronos How can it be configured to display like this?

Hi, mate!
That will be the normal behavior. It's not necessary any specific configuration.
I just think that it's not deployed on production yet.

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

Labels

cla-signed The user has signed the Contributor License Agreement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

collapsed line in go (and other languages) should be on one line

3 participants