# editor: Fix folding for unindented multiline strings and comments \(\#50049\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/735eb4340dfae4001a72589aad1cd39642f4d1f9)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: 735eb4340dfae4001a72589aad1cd39642f4d1f9

Requested commit: 735eb4340dfae4001a72589aad1cd39642f4d1f9

Commit: 735eb4340dfae4001a72589aad1cd39642f4d1f9

Tree: 3515a08c0f1aa13c356ef9f18c3695442cc464fd

Author: Ryan Walker

Committer: GitHub

## Message

````
editor: Fix folding for unindented multiline strings and comments (#50049)

Closes #5057

## Summary

The indent-based code fold detection does not account for lines inside
multiline strings or block comments that have less indentation than the
surrounding code. This causes the fold scanner to think the enclosing
block ends prematurely.

For example, folding `fn main()` here would fail because the raw string
content at indent level 0 gets treated as the end of the function body:

``` rust
fn main() {
    let s = r#"
unindented content
"#;
}  
```

This PR checks whether a low-indent line falls inside a string or
comment override region and skips it if so. This works across all
languages that define `@string` or `@comment` overrides in their
`overrides.scm`.

## Before


https://github.com/user-attachments/assets/a08e6bf8-4f25-4211-8a46-8f6da7e49247

## After


https://github.com/user-attachments/assets/cd5b36db-6d4d-420b-9d60-79f9fad8638e

## Test Plan

- Added `test_fold_with_unindented_multiline_raw_string`
- Added `test_fold_with_unindented_multiline_block_comment`
- All existing fold tests pass
- Manually tested both Rust and Python examples

Release Notes:

- Fixed code folding incorrectly collapsing when multiline strings or
block comments contained unindented content
````

## Parents

- [e5150abe6f6ed1f7c8a5420ce66f20921ba19110](https://git.cafe/gitcafe/zed/commit/e5150abe6f6ed1f7c8a5420ce66f20921ba19110?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/735eb4340dfae4001a72589aad1cd39642f4d1f9?format=markdown)
