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

Empty lines should be ignored when comment/uncomment code #81474

Closed
jsjtxietian opened this issue Sep 9, 2023 · 2 comments · Fixed by #81486
Closed

Empty lines should be ignored when comment/uncomment code #81474

jsjtxietian opened this issue Sep 9, 2023 · 2 comments · Fixed by #81486

Comments

@jsjtxietian
Copy link
Contributor

jsjtxietian commented Sep 9, 2023

Godot version

Godot v4.2.dev (fc99492)

System information

Windows 10.0.22621 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 3060 Ti (NVIDIA; 31.0.15.3699) - 12th Gen Intel(R) Core(TM) i7-12700F (20 Threads)

Issue description

  1. Inserting a newline in the commented code and then uncomment all of them won't work, godot will think the new line (usually just a '\t' or '\n') is uncommented, so it assumes the whole code block is uncommented and will comment all the code again.
  2. Comment will work when comment a empty line, by empty I mean the line only consist of '\t' '\n' and ' '

Steps to reproduce

For 1, write some code like this:

	var a = 1
	var b = 2

comment them by ctrl + k, and press enter after #var a = 1 to make a new line, it should look like this:

	#var a = 1
		
	#var b = 2

And uncomment all the three lines together, you will get this instead of uncommentting all the lines

	##var a = 1
#
	##var b = 2

For 2, it's trivial to reproduce.

Minimal reproduction project

Any project should work.

I has already fixed it in my local branch, but I think it need mroe disscussion about which behavior is intented and which is not.
I can understand the behaviour of point 2 to some extent but point 1 really brings inconvenience.

After the disscussion, I can update my fix and create a pr for it if necessary.

@timothyqiu
Copy link
Member

timothyqiu commented Sep 9, 2023

I think ignoring empty lines makes sense when uncommenting. VS Code and commentary.vim also work like this.

I don't mind being able to comment an empty line.

@jsjtxietian
Copy link
Contributor Author

jsjtxietian commented Sep 9, 2023

I found an interesting case relating the detail of this code logic, in the code godot will first decide it is a comment behaviour or uncomment behaviour based on whether any line doesn't contain a '#'.

But when the code you want to operate only contains empty line, the origin logic will break if we just ignore empty lines, I added a special case in the code, take a look and your suggestions are welcomed.

@AThousandShips AThousandShips changed the title Empty lines should be ignored when comment/uncommet code Empty lines should be ignored when comment/uncomment code Sep 9, 2023
@akien-mga akien-mga added this to the 4.2 milestone Sep 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants