zed/crates/language
Apoorva Verma d9ada8487b
Fix hard-tab block autoindent skipping unindented lines (#60406)
# Objective

Fixes #59979

With hard tabs on, expanding a multi-line snippet only re-indents the
lines that already start with a tab. Anything with no leading whitespace
(closing brackets, mostly) stays at column 0.

## Solution

Block autoindent shifts each line by the first line's delta, but only
when the line's indent kind matches the target kind. A line with no
indentation defaults to `IndentKind::Space`, so under hard tabs it never
matches and gets skipped. An empty indent doesn't really have a kind, so
I let it adopt the target kind before the check. Lines that actually
have space indentation in a tab buffer are still left alone. Normalizing
those felt like a bigger question than this bug, happy to look at it
separately if wanted.

## Testing

New `test_autoindent_block_mode_with_hard_tabs`, same shape as the
snippet in the issue. Fails on main (closing brace stays at column 0),
passes with the fix. `cargo test -p language` and `-p editor` are green,
clippy and fmt too.

## 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 multi-line snippets leaving unindented lines at column 0 when
`hard_tabs` is enabled.
2026-07-07 07:45:54 +00:00
..
benches Extract language_core and grammars crates from language (#52238) 2026-03-25 23:41:09 +00:00
src Fix hard-tab block autoindent skipping unindented lines (#60406) 2026-07-07 07:45:54 +00:00
build.rs
Cargo.toml Anchor sticky scroll to symbol name rows (#56333) 2026-06-15 11:03:26 +00:00
LICENSE-GPL