Fix pressing Tab after mid-line selection replacing it with indentation
Closes #22757
Release Notes:
- Fixed behavior where pressing the Tab key with a selection always indented the entire line(s), regardless of what part of the line was selected.
- Updated the indentation logic to distinguish between: selections that include an entire line or span multiple lines -> indents the entire line(s); mid-line selections (not including the first character of any line) -> replaces the selected text with an indentation string
- Added a new
test_indent_selection_behaviorto validate this behavior and prevent regressions.
While investigating the issue, I confirmed that Zed did not differentiate between line-level and mid-line selections when indenting. This caused confusion when selecting and pressing Tab, especially for users familiar with behavior in editors like VSCode.
The fix adjusts the indent_selection logic to:
- Check if the selection starts at column 0, ends at the last character of the line, or spans multiple lines.
- Indent whole lines only in those cases.
- Otherwise, the selected text is replaced with the appropriate indent (spaces or tabs based on user settings).
The updated test ensures both behaviors are properly covered.
Demo: https://github.com/user-attachments/assets/b46fc11e-726e-4c09-8016-db598e1ce195
| Warnings | |
|---|---|
| :warning: |
This PR is missing release notes. Please add a "Release Notes" section that describes the change:
If your change is not user-facing, you can use "N/A" for the entry:
|
Generated by :no_entry_sign: dangerJS against ffdaeb584fb67823463d9e8486856ccbc83647e8
Tests were never fixed in a month, so I'll close this as stale for now.
Hey! I lost access to my github account 3 weeks ago and could only recover it now, if you could be able to open the PR again I could work on fixing the tests asap. I'm really sorry for the inconvenience.
No worries at all.
This is stale, after all — it's fine, just reopen a new PR when the time comes and you're still interested in this.