"Toggle Comments" inserts `//` slashes in the wrong place

Originator:julian.dunskus
Number:rdar://45994607 Date Originated:12-Nov-2018 07:36 PM
Status:Open Resolved:
Product:iOS + SDK Product Version:10.1
Classification:Other Bug Reproducible:Always
 
Summary:
The “Toggle Comments” command, when turning comments on for a line, simply inserts two slashes at the start of the line, without considering indentation or whitespace.

This has the consequence that running “Re-Indent” on it indents the slashes to the appropriate indentation level, thus leaving you with the indentation repeated twice, once before and once after the slashes.

I’d prefer if it instead inserted the slashes immediately before the first non-whitespace character, or perhaps according to the line’s inferred indentation. (The former would probably play nicer with people not using Xcode’s indentation.)

Steps to Reproduce:
1. Write/Find some code that is indented by at least one level and position the cursor in or select it.
2. “Toggle Comments”, e.g. by pressing its menu item.

Expected Results:
The slashes are right before the first non-whitespace character on each line.

Actual Results:
The slashes are at the start of the line, before any indentation.

Version:
10.1

Notes:
The only scenario inserting the slashes before the indentation would be useful is if you never had indentation before your comments. Aside from not working well for non-code comments (imo), this use case is immediately invalidated by “Re-Indent” not even having the option to align comments that way.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!