()
| 2108 | |
| 2109 | |
| 2110 | protected void handleCommentUncomment() { |
| 2111 | // log("Entering handleCommentUncomment()"); |
| 2112 | startCompoundEdit(); |
| 2113 | |
| 2114 | String prefix = getCommentPrefix(); |
| 2115 | int prefixLen = prefix.length(); |
| 2116 | |
| 2117 | int startLine = textarea.getSelectionStartLine(); |
| 2118 | int stopLine = textarea.getSelectionStopLine(); |
| 2119 | |
| 2120 | int lastLineStart = textarea.getLineStartOffset(stopLine); |
| 2121 | int selectionStop = textarea.getSelectionStop(); |
| 2122 | // If the selection ends at the beginning of the last line, |
| 2123 | // then don't (un)comment that line. |
| 2124 | if (selectionStop == lastLineStart) { |
| 2125 | // Though if there's no selection, don't do that |
| 2126 | if (textarea.isSelectionActive()) { |
| 2127 | stopLine--; |
| 2128 | } |
| 2129 | } |
| 2130 | |
| 2131 | // If the text is empty, ignore the user. |
| 2132 | // Also ensure that all lines are commented (not just the first) |
| 2133 | // when determining whether to comment or uncomment. |
| 2134 | boolean commented = true; |
| 2135 | for (int i = startLine; commented && (i <= stopLine); i++) { |
| 2136 | String lineText = textarea.getLineText(i).trim(); |
| 2137 | if (lineText.length() == 0) { |
| 2138 | continue; //ignore blank lines |
| 2139 | } |
| 2140 | commented = lineText.startsWith(prefix); |
| 2141 | } |
| 2142 | |
| 2143 | // log("Commented: " + commented); |
| 2144 | |
| 2145 | // This is the min line start offset of the selection, which is added to |
| 2146 | // all lines while adding a comment. Required when commenting |
| 2147 | // lines which have uneven whitespaces in the beginning. Makes the |
| 2148 | // commented lines look more uniform. |
| 2149 | int lso = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(startLine) |
| 2150 | - textarea.getLineStartOffset(startLine)); |
| 2151 | |
| 2152 | if (!commented) { |
| 2153 | // get min line start offset of all selected lines |
| 2154 | for (int line = startLine+1; line <= stopLine; line++) { |
| 2155 | String lineText = textarea.getLineText(line); |
| 2156 | if (lineText.trim().length() == 0) { |
| 2157 | continue; //ignore blank lines |
| 2158 | } |
| 2159 | int so = Math.abs(textarea.getLineStartNonWhiteSpaceOffset(line) |
| 2160 | - textarea.getLineStartOffset(line)); |
| 2161 | lso = Math.min(lso, so); |
| 2162 | } |
| 2163 | } |
| 2164 | |
| 2165 | for (int line = startLine; line <= stopLine; line++) { |
| 2166 | int location = textarea.getLineStartNonWhiteSpaceOffset(line); |
| 2167 | String lineText = textarea.getLineText(line); |
no test coverage detected