(boolean indent)
| 1851 | |
| 1852 | |
| 1853 | public void handleIndentOutdent(boolean indent) { |
| 1854 | int tabSize = Preferences.getInteger("editor.tabs.size"); |
| 1855 | String tabString = Editor.EMPTY.substring(0, tabSize); |
| 1856 | |
| 1857 | startCompoundEdit(); |
| 1858 | |
| 1859 | int startLine = textarea.getSelectionStartLine(); |
| 1860 | int stopLine = textarea.getSelectionStopLine(); |
| 1861 | |
| 1862 | // If the selection ends at the beginning of the last line, |
| 1863 | // then don't (un)comment that line. |
| 1864 | int lastLineStart = textarea.getLineStartOffset(stopLine); |
| 1865 | int selectionStop = textarea.getSelectionStop(); |
| 1866 | if (selectionStop == lastLineStart) { |
| 1867 | // Though if there's no selection, don't do that |
| 1868 | if (textarea.isSelectionActive()) { |
| 1869 | stopLine--; |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | for (int line = startLine; line <= stopLine; line++) { |
| 1874 | int location = textarea.getLineStartOffset(line); |
| 1875 | |
| 1876 | if (indent) { |
| 1877 | textarea.select(location, location); |
| 1878 | textarea.setSelectedText(tabString); |
| 1879 | |
| 1880 | } else { // outdent |
| 1881 | int last = Math.min(location + tabSize, textarea.getDocumentLength()); |
| 1882 | textarea.select(location, last); |
| 1883 | // Don't eat code if it's not indented |
| 1884 | if (tabString.equals(textarea.getSelectedText())) { |
| 1885 | textarea.setSelectedText(""); |
| 1886 | } |
| 1887 | } |
| 1888 | } |
| 1889 | // Subtract one from the end, otherwise selects past the current line. |
| 1890 | // (Which causes subsequent calls to keep expanding the selection) |
| 1891 | textarea.select(textarea.getLineStartOffset(startLine), |
| 1892 | textarea.getLineStopOffset(stopLine) - 1); |
| 1893 | stopCompoundEdit(); |
| 1894 | sketch.setModified(true); |
| 1895 | } |
| 1896 | |
| 1897 | |
| 1898 | static public boolean checkParen(char[] array, int index, int stop) { |
no test coverage detected