Improve auto indentation in situations with multiline comments present (#61669)
## Objective
Fix incorrect indentation after multiline comments and when pasting
multiline code immediately after a comment.
Fixes #61668
Fixes #55597
## Solution
- Calculate logical indentation from the opening line of block comments,
documentation comments, and multiline strings.
- Reuse the logical indentation for both newline handling and multiline
paste auto-indent.
- Preserve the relative indentation of pasted multiline content while
using the logical indentation of the surrounding code as its basis.
## Testing
- `cargo test -p editor --lib test_newline -- --nocapture`
- `cargo test -p editor --lib test_paste -- --nocapture`
- `cargo test -p language --lib test_autoindent -- --nocapture`
- `./script/clippy -p language`
- `./script/clippy -p editor`
- Regression coverage includes Go, TypeScript, and Python comment/string
indentation, plus Go multiline paste after a documentation comment.
- No platform-specific behavior is involved; the fix is implemented in
shared editor and language auto-indent logic.
The demonstration video is as follows:
https://github.com/user-attachments/assets/2a2ee494-d4ea-4b16-8644-f868b9f31272
https://github.com/user-attachments/assets/9487f893-e584-448d-a1c7-a94c76c03f5b
## Self-Review Checklist:
- [x] I've reviewed my own diff for quality, security, and reliability
- [x] Unsafe blocks (if any) have justifying comments
- [x] The content adheres to Zed's UI standards
([UX/UI](https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md#uiux-checklist)
and
[icon](https://github.com/zed-industries/zed/blob/main/crates/icons/README.md)
guidelines
- [x] Tests cover the new/changed behavior
- [x] Performance impact has been considered and is acceptable
---
Release Notes:
- Fixed incorrect indentation after multiline comments and multiline
paste.
4a9a863ceeYifeng Xu committed on 8/26/2026, 2:33:25 PM· committed by GitHubparentea701d4