(boolean indent)
| 2198 | |
| 2199 | |
| 2200 | public void handleIndentOutdent(boolean indent) { |
| 2201 | int tabSize = Preferences.getInteger("editor.tabs.size"); |
| 2202 | String tabString = Editor.EMPTY.substring(0, tabSize); |
| 2203 | |
| 2204 | startCompoundEdit(); |
| 2205 | |
| 2206 | int startLine = textarea.getSelectionStartLine(); |
| 2207 | int stopLine = textarea.getSelectionStopLine(); |
| 2208 | |
| 2209 | // If the selection ends at the beginning of the last line, |
| 2210 | // then don't (un)comment that line. |
| 2211 | int lastLineStart = textarea.getLineStartOffset(stopLine); |
| 2212 | int selectionStop = textarea.getSelectionStop(); |
| 2213 | if (selectionStop == lastLineStart) { |
| 2214 | // Though if there's no selection, don't do that |
| 2215 | if (textarea.isSelectionActive()) { |
| 2216 | stopLine--; |
| 2217 | } |
| 2218 | } |
| 2219 | |
| 2220 | for (int line = startLine; line <= stopLine; line++) { |
| 2221 | int location = textarea.getLineStartOffset(line); |
| 2222 | |
| 2223 | if (indent) { |
| 2224 | textarea.select(location, location); |
| 2225 | textarea.setSelectedText(tabString); |
| 2226 | |
| 2227 | } else { // outdent |
| 2228 | int last = Math.min(location + tabSize, textarea.getDocumentLength()); |
| 2229 | textarea.select(location, last); |
| 2230 | // Don't eat code if it's not indented |
| 2231 | if (tabString.equals(textarea.getSelectedText())) { |
| 2232 | textarea.setSelectedText(""); |
| 2233 | } |
| 2234 | } |
| 2235 | } |
| 2236 | // Subtract one from the end, otherwise selects past the current line. |
| 2237 | // (Which causes subsequent calls to keep expanding the selection) |
| 2238 | textarea.select(textarea.getLineStartOffset(startLine), |
| 2239 | textarea.getLineStopOffset(stopLine) - 1); |
| 2240 | stopCompoundEdit(); |
| 2241 | sketch.setModified(true); |
| 2242 | } |
| 2243 | |
| 2244 | |
| 2245 | static public boolean checkParen(char[] array, int index, int stop) { |
no test coverage detected