From 12790d267ea7b1ee9ff1699d3812ddfa648ff342 Mon Sep 17 00:00:00 2001 From: Jakub Valtar Date: Thu, 20 Jul 2017 17:50:59 +0200 Subject: [PATCH] Fix comment/uncomment adding slashes at wrong indent Fixes #5171 --- app/src/processing/app/ui/Editor.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index 4cdc9817a..a52650ea9 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2136,13 +2136,26 @@ public abstract class Editor extends JFrame implements RunnerListener { // log("Commented: " + commented); - // This is the line start offset of the first line, which is added to - // all other lines while adding a comment. Required when commenting + // This is the min line start offset of the selection, which is added to + // all lines while adding a comment. Required when commenting // lines which have uneven whitespaces in the beginning. Makes the // commented lines look more uniform. int lso = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(startLine) - textarea.getLineStartOffset(startLine)); + if (!commented) { + // get min line start offset of all selected lines + for (int line = startLine+1; line <= stopLine; line++) { + String lineText = textarea.getLineText(line); + if (lineText.trim().length() == 0) { + continue; //ignore blank lines + } + int so = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(line) + - textarea.getLineStartOffset(line)); + lso = Math.min(lso, so); + } + } + for (int line = startLine; line <= stopLine; line++) { int location = textarea.getLineStartNonWhiteSpaceOffset(line); String lineText = textarea.getLineText(line);