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

:reflow messes up tab-indented comments #3622

Open
mtoohey31 opened this issue Sep 1, 2022 · 0 comments
Open

:reflow messes up tab-indented comments #3622

mtoohey31 opened this issue Sep 1, 2022 · 0 comments
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug upstream

Comments

@mtoohey31
Copy link
Contributor

mtoohey31 commented Sep 1, 2022

Summary

When :reflow is used with comments that are indented via spaces, it correctly maintains the common prefix on all lines. However, with tabs, it treats the tabs and the comment prefix as if they were regular characters, and ends up breaking the comment.

Reproduction Steps

I tried this:

  1. Write the following to a file (ensuring that tab-indentation is used):
// main.go
package main

func main() {
	// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
	// tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
	// veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
	// commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
	// velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
	// occaecat cupidatat non proident, sunt in culpa qui officia deserunt
	// mollit anim id est laborum.
	println("Hello, world!")
}
  1. hx main.go
  2. Select comment
  3. :reflow 100

I expected this to happen:

The document becomes something like:

package main

func main() {
	// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt
	// ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco
	// laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit
	// in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat
	// cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
	println("Hello, world!")
}

Instead, this happened:

The document becomes:

package main

func main() {
	// Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod 	// tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim 	// veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea 	// commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
	// velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint 	// occaecat cupidatat non
proident, sunt in culpa qui officia deserunt 	// mollit anim id est laborum.
	println("Hello, world!")
}

Helix log

No response

Platform

Linux

Terminal Emulator

kitty 0.25.2

Helix Version

22.05-440-ge0667827


Edit: I am working on a fix for this, just thought I'd post this for a clear explanation of the motivation for the eventual PR.

Edit 2: Also, now that I've looked into the code, it looks like tab-width is totally unaccounted for too. Tabs currently count as zero width 😬.

@mtoohey31 mtoohey31 added the C-bug Category: This is a bug label Sep 1, 2022
@the-mikedavis the-mikedavis added the A-helix-term Area: Helix term improvements label Sep 1, 2022
@kirawi kirawi added the upstream label Sep 4, 2022
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 21, 2024
This uses the single-line comment prefixes from the language config,
so it should be able to handle different languages in a robust way. The
logic is fairly simple, and doesn't handle block comments, for example.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 21, 2024
This uses the single-line comment prefixes from the language config,
so it should be able to handle different languages in a robust way. The
logic is fairly simple, and doesn't handle block comments, for example.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 21, 2024
This uses the single-line comment prefixes from the language config,
so it should be able to handle different languages in a robust way. The
logic is fairly simple, and doesn't handle block comments, for example.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 21, 2024
This uses the single-line comment prefixes from the language config,
so it should be able to handle different languages in a robust way. The
logic is fairly simple, and doesn't handle block comments, for example.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 22, 2024
I changed :reflow to use the DocumentFormatter object instead of the
textwrap crate. This allows using the same logic for soft wrap as
for :reflow. Because the logic is the same as for soft wrap, we end up
preserving all existing newlines, so it's more like "wrap" than reflow,
but I think this behavior makes sense anyway to avoid extraneous diffs.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 22, 2024
I changed :reflow to use the DocumentFormatter object instead of the
textwrap crate. This allows using the same logic for soft wrap as
for :reflow. Because the logic is the same as for soft wrap, we end up
preserving all existing newlines, so it's more like "wrap" than reflow,
but I think this behavior makes sense anyway to avoid extraneous diffs.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 22, 2024
I changed :reflow to use the DocumentFormatter object instead of the
textwrap crate. This allows using the same logic for soft wrap as
for :reflow. Because the logic is the same as for soft wrap, we end up
preserving all existing newlines, so it's more like "wrap" than reflow,
but I think this behavior makes sense anyway to avoid extraneous diffs.

Fixes helix-editor#3332, helix-editor#3622
rhogenson pushed a commit to rhogenson/helix that referenced this issue Sep 22, 2024
I changed :reflow to use the DocumentFormatter object instead of the
textwrap crate. This allows using the same logic for soft wrap as
for :reflow. Because the logic is the same as for soft wrap, we end up
preserving all existing newlines, so it's more like "wrap" than reflow,
but I think this behavior makes sense anyway to avoid extraneous diffs.

Fixes helix-editor#3332, helix-editor#3622
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-helix-term Area: Helix term improvements C-bug Category: This is a bug upstream
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants