zed icon indicating copy to clipboard operation
zed copied to clipboard

Fix pressing Tab after mid-line selection replacing it with indentation

Open PedroRuanoS opened this issue 10 months ago • 4 comments

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_behavior to 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

PedroRuanoS avatar Apr 07 '25 17:04 PedroRuanoS

Warnings
:warning:

This PR is missing release notes.

Please add a "Release Notes" section that describes the change:

Release Notes:

- Added/Fixed/Improved ...

If your change is not user-facing, you can use "N/A" for the entry:

Release Notes:

- N/A

Generated by :no_entry_sign: dangerJS against ffdaeb584fb67823463d9e8486856ccbc83647e8

zed-industries-bot avatar Apr 11 '25 15:04 zed-industries-bot

Tests were never fixed in a month, so I'll close this as stale for now.

SomeoneToIgnore avatar May 05 '25 21:05 SomeoneToIgnore

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.

PedroRuanoS avatar May 06 '25 20:05 PedroRuanoS

No worries at all.

SomeoneToIgnore avatar May 07 '25 05:05 SomeoneToIgnore

This is stale, after all — it's fine, just reopen a new PR when the time comes and you're still interested in this.

SomeoneToIgnore avatar May 26 '25 06:05 SomeoneToIgnore