Soft wrap and rewrap break at different places
With the same text triggering a editor::rewrap and letting zed soft wrap will break the lines at different locations. E.g. rewrap will generate lines that are 80 chars long, while softwrap will wrap the same text following the 79 character.
Original Issue as reported
Check for existing issues
- [X] Completed
Describe the bug / provide steps to reproduce it
When using soft wrapping in bounded mode or preferred_line_length mode, I noticed that rewrapping text sometimes results in lines that still get soft wrapped. This seems to be caused by the fact that soft wrapping happens one character sooner than rewrapping. I would expect these to be consistent, such that rewrapping a text means it doesn't get soft wrapped anymore.
Here's the relevant config options:
"preferred_line_length": 80,
"soft_wrap": "bounded",
And a sample text that demonstrates the issue for line length of 80:
Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt.
Here is is before rewrapping:
And after:
Notice how the cursor is at the end of the soft wrapped line and this is position 80. I guess the soft wrapping actually gives a max line length of 79 but rewrapping includes the 80th character when that's where a word ends.
Zed Version and System Specs
Zed: v0.166.1 (Zed Preview) OS: Arch Linux X11 Memory: 23.2 GiB Architecture: x86_64 GPU: Intel(R) UHD Graphics 620 (KBL GT2) || Intel open-source Mesa driver || Mesa 24.2.5-arch1.1
If applicable, add screenshots or screencasts of the incorrect state / behavior
No response
If applicable, attach your Zed.log file to this issue.
Zed.log
Simple reproduce of the issue you are describing. With the following settings:
"preferred_line_length": 80,
"soft_wrap": "bounded",
- Paste this into a buffer.
Child: Mister Owl, how many licks does it take to get to the tootsie roll center of a tootsie pop?
- Trigger
editor::Rewrap - Paste again Results:
Expected results: hard wrapped version of text and soft wrapped version of some text should be displayed identically.
This issue is still valid, reproduced in 0.184.9 as described in the 2nd comment above.
Removing the bite-size label after discussion with @maxbrunsfeld. We should change how soft wrap behaves here, but it's slightly tricky. Notes:
- We can't make soft wrap and
editor::Rewrapagree in all cases, becauseeditor::Rewrapis allowed to remove space characters, while soft wrap must preserve the ability to put your cursor on every space character in the original text. - It would be good to allow soft wrap to put the space character after
centeron the first line in Peter's example, where it's technically past the wrap limit, instead of forcing it to backtrack to the beginning ofcenterlike it does now. (We definitely shouldn't put the space character at the start of the second line.) - But we shouldn't do that in
SoftWrap::EditorWidthmode, because it would result in a horizontal scroll. So we need to extend this code to pass down two widths instead of one in theSoftWrap::Boundedcase, and propagate that down toLineWrapper::wrap_line.