Skip to content

Commit 4813be6

Browse files
committed
Fix comment/uncomment adding slashes at wrong indent
Fixes #5171
1 parent fa2d64a commit 4813be6

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

app/src/processing/app/ui/Editor.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2136,13 +2136,26 @@ protected void handleCommentUncomment() {
21362136

21372137
// log("Commented: " + commented);
21382138

2139-
// This is the line start offset of the first line, which is added to
2140-
// all other lines while adding a comment. Required when commenting
2139+
// This is the min line start offset of the selection, which is added to
2140+
// all lines while adding a comment. Required when commenting
21412141
// lines which have uneven whitespaces in the beginning. Makes the
21422142
// commented lines look more uniform.
21432143
int lso = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(startLine)
21442144
- textarea.getLineStartOffset(startLine));
21452145

2146+
if (!commented) {
2147+
// get min line start offset of all selected lines
2148+
for (int line = startLine+1; line <= stopLine; line++) {
2149+
String lineText = textarea.getLineText(line);
2150+
if (lineText.trim().length() == 0) {
2151+
continue; //ignore blank lines
2152+
}
2153+
int so = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(line)
2154+
- textarea.getLineStartOffset(line));
2155+
lso = Math.min(lso, so);
2156+
}
2157+
}
2158+
21462159
for (int line = startLine; line <= stopLine; line++) {
21472160
int location = textarea.getLineStartNonWhiteSpaceOffset(line);
21482161
String lineText = textarea.getLineText(line);

0 commit comments

Comments
 (0)