Sublime Forum

toggleComment bug

#1

bug on last change of toggleComment, if you use ctrl+/ on an empty line, you expect to have a new comment, but nothing happen.

1 Like

#2

If only an empty line is selected, then this works for me, at least for Python files.

If both non-empty and empty lines are selected, the only the non-empty lines get commented. This is by design, so that all the inserted comment markers can be vertically aligned.

0 Likes

#3

doesn’t work for me… guess i’ll have to check why

0 Likes

#4

i have checked it on a PC with no previous install of sublime text, and no additional packages, and i get the same behavior (checked by opening the default key binding, locating the courser on an empty line and pressing ctrl+/ - nothing happen)

can anyone confirm this?

0 Likes

#5

[quote=“vim”]i have checked it on a PC with no previous install of sublime text, and no additional packages, and i get the same behavior (checked by opening the default key binding, locating the courser on an empty line and pressing ctrl+/ - nothing happen)

can anyone confirm this?[/quote]

I can confirm and add some more info…
Toggle comment only works in blank lines when the blank line is the LAST line… otherwise it fails… this applies to everything, I tested python, php, html, and css…

So if you have a blank document with one line of course it’ll work, add couple blank lines now go to another line that is not the last one, and fail…
also it doesn’t matter if the line is selected or not…

0 Likes

#6

As of now, with ST3 Build 3126 I am still experiencing this issue (or designed behavior…).

When using toggle comment on a mixed selection, only the non-blank lines are commented.
Used on only blank lines, these lines are commented.

To me, this behavior is rather un-intuitive, but I guess a matter of taste.
For some “languages” or file formats, though, this is really an issue because blank lines can change the interpretation of files in certain programs (I a specifically talking about FEM solvers like LS-Dyna).

I would really like to see an option which can control that behavior.
The most elegant way I think to control this would be through an option for the Comments.tmPreferences file (similar to the TM_COMMENT_DISABLE_INDENT option).
This way the behavior can easily be changed for different language/file syntaxes.

0 Likes

#7

For the record, you can modify this behavior by directly editing Default/comment.py (via PackageResourceViewer).

Change line 148-149 from:

        non_empty_start_positions = list(filter(
            lambda p: has_non_white_space_on_line(view, p), start_positions))

to:

        non_empty_start_positions = start_positions
2 Likes

#8

Sweet! Thank you so much. That works like a charm! :+1:

0 Likes

#9

Created an account just to say, Thanks!

0 Likes