Sublime Forum

Indentation Not Intelligently Restored When Toggling Comments in Some Cases

#1

So I think this is a recent change/breakage, but I’m not totally sure.

It’s best to illustrate this with examples. For all of these I’m using a clean install of build 3148 with no plugins, and I have indentation width set to 2 and to be done with spaces.

Anywho, if I have the ruby code:

class MyClass
  def initialize(*args)
    #my_method(*args) do |foo|
      #other_method(foo)
    #end
  end
end

… and I run the “Toggle Comment” on the commented lines, I get:

class MyClass
  def initialize(*args)
    my_method(*args) do |foo|
      other_method(foo)
    end
  end
end

… everything is A-OK.

But if instead, I run “Toggle Comment” on the commented lines and the comments are like:

class MyClass
  def initialize(*args)
    #my_method(*args) do |foo|
    #  other_method(foo)
    #end
  end
end

… I get this:

class MyClass
  def initialize(*args)
    my_method(*args) do |foo|
     other_method(foo)
    end
  end
end

If it’s not visible, a space is missing from the indentation in the middle commented line. This is obviously not expected behavior. ST3 though should know not to restore any uncommented line such that the text begins at a position that isn’t a multiple of the tab width. (And if it were going to, it should round up.)

0 Likes

#2

Did you try with 3149, too?

Just pasted your code to my ST and tried to reproduce without luck. Indention is preserved as expected.

0 Likes

#3

Just did. Having same exact problem.

Are you sure you set everything as I described? The only other thing that I didn’t mention (as I thought was obvious) was I set the syntax to ruby. (Commenting doesn’t work at all if the syntax isn’t set.)

I used a user on my machine that had never used sublime before (to the extent I had to re-enter my license key), so I know it was a clean install. Could it be something on my system generally that is affecting reproducibility? (I’m running the latest Ubuntu and happy to offer more details if that were to help…)

0 Likes

#4

Hi,
Could someone please look at this again and try to repro? I just tried this on a clean install (on Windows this time) of the latest ST3 and I’m still having this problem.

Simply:

  • Make sure “Indent Using Spaces” is ON

  • Copy/paste this into a new file:

    class MyClass
    def initialize(*args)
    #my_method(*args) do |foo|
    # other_method(foo)
    #end
    end
    end

  • Change the syntax to Ruby.

  • Highlight the three commented lines.

  • Either go to Edit -> Comment -> Toggle Comment or hit Ctrl-/.

After doing this, you will see that the line that reads other_method(foo) is indented with one less space than it should be.

Thanks

0 Likes