Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrap incorrectly accounts for tabs #18686

Open
1 task done
andreyvit opened this issue Oct 3, 2024 · 0 comments
Open
1 task done

Rewrap incorrectly accounts for tabs #18686

andreyvit opened this issue Oct 3, 2024 · 0 comments
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc

Comments

@andreyvit
Copy link

Check for existing issues

  • Completed

Describe the bug / provide steps to reproduce it

The new Rewrap command from #17909 produces a line that soft-wraps in the editor when using tabs:

Screenshot 2024-10-03 at 1 10 25 PM

The above is produced with preferred_line_length=80 soft_wrap=preferred_line_length (and I assume tab_size=4 by default for Go) and after invoking Rewrap.

Golang always uses tabs for indentation, so the issue is most relevant for Go code.

Environment

Zed: v0.155.2 (Zed)
OS: macOS 14.1.1
Memory: 24 GiB
Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

Looking at the code, Rewrap clearly deals in characters; current_line.len() + word.len() >= wrap_column condition doesn't account for tab characters.

An easy fix would be to count the tabs and subtract (tab_count * (tab-size - 1)) from the left-hand side of that comparison. Of course, expanding tabs correctly would be even better, in case those are mixed with spaces.

(Also I'm wondering that Rewrap has to implement its own wrapping. This seems perilous. Zed already has code to wrap text correctly somewhere, I wish we could reuse that.)

If applicable, attach your Zed.log file to this issue.

Zed.log
@andreyvit andreyvit added admin read Pending admin review defect [core label] triage Maintainer needs to classify the issue labels Oct 3, 2024
@JosephTLyons JosephTLyons added editor Feedback for code editing, formatting, editor iterations, etc and removed triage Maintainer needs to classify the issue admin read Pending admin review labels Oct 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
defect [core label] editor Feedback for code editing, formatting, editor iterations, etc
Projects
None yet
Development

No branches or pull requests

2 participants