Dan
Dan

Reputation: 1697

How to fix Xcode 4's useless uncommenting behavior

In Xcode 4, selecting the Uncomment command only works properly if the comment slashes are at the beginning of the line.

So using ⌘/ on this line:

// sudo make me a sandwich

results in this:

sudo make me a sandwich

But when the comment is indented:

    //sudo make me a sandwich

⌘/ results in this:

//    //sudo make me a sandwich

If my cursor is in a line that is a comment, I want ⌘/ to uncomment it. Period. Does anyone have a workaround/fix for this?

Upvotes: 13

Views: 3375

Answers (2)

Joshua Jabbour
Joshua Jabbour

Reputation: 592

As of Xcode 6 (at least), this now works.

It does have the caveat, however, of not automatically aligning uncommented code.

In this example

    func doSomething() {
        doSomethingElse()
//        someOtherThing()
        //alertUser()
        // logTask()
    }

Hitting cmd-/ will on each of the commented lines results in:

    func doSomething() {
        doSomethingElse()
        someOtherThing()
        alertUser()
         logTask()
    }

So in effect, Xcode is only removing the //, not adjusting the whitespace to properly align the lines. If you comment out lines without adding additional whitespace, all will work perfectly. I however, add the extra space after comments to make that line more readable, and so this still contains a bug (or feature request) for me...

Upvotes: 0

BJ Homer
BJ Homer

Reputation: 49034

Two solutions:

  1. Cmd-[ a few times to un-indent it, then Cmd-/ to uncomment, then Ctrl-i to re-indent it. A little lame, but you asked for a workaround, and there it is.
  2. File a bug at bugreport.apple.com, so that it can be brought to the attention of the engineers and fixed in a future release.

Upvotes: 16

Related Questions