fix comment/uncomment to only uncomment when all are commented out

This commit is contained in:
benfry
2008-08-16 14:24:54 +00:00
parent 15cdadb3b6
commit 6466d0fda5
2 changed files with 16 additions and 9 deletions

View File

@@ -1176,13 +1176,21 @@ public class Editor extends JFrame {
}
// If the text is empty, ignore the user.
// Also ensure that all lines are commented (not just the first)
// when determining whether to comment or uncomment.
int length = textarea.getDocumentLength();
int pos = textarea.getLineStartOffset(startLine);
if (pos + 2 > length) return;
// Check the first two characters to see if it's already a comment.
String begin = textarea.getText(pos, 2);
//System.out.println("begin is '" + begin + "'");
boolean commented = begin.equals("//");
boolean commented = true;
for (int i = startLine; commented && (i <= stopLine); i++) {
int pos = textarea.getLineStartOffset(i);
if (pos + 2 > length) {
commented = false;
} else {
// Check the first two characters to see if it's already a comment.
String begin = textarea.getText(pos, 2);
//System.out.println("begin is '" + begin + "'");
commented = begin.equals("//");
}
}
for (int line = startLine; line <= stopLine; line++) {
int location = textarea.getLineStartOffset(line);

View File

@@ -1,6 +1,8 @@
0146 pde
X fix problem with comment/uncomment and indent/outdent
X when no selection, and on the first pos of the line
X on comment/uncomment, need to check if *all* lines are commented
X otherwise should be comment (never uncomment unless all selected)
runner
X use debugger to get better exceptions
@@ -14,9 +16,6 @@ X probably b/c not catching ex inside the run() method
X getMessage() not sufficient for exceptions coming through
X get actual message text, plus the exception itself
_ on comment/uncomment, need to check if *all* lines are commented
_ otherwise should be comment (never uncomment unless all selected)
cleaning
X NullPointerException inside setup() comes up weird
X because NullPointerException is a RuntimeException