MCPcopy Index your code
hub / github.com/benfry/processing4 / handleIndentOutdent

Method handleIndentOutdent

app/src/processing/app/ui/Editor.java:1853–1895  ·  view source on GitHub ↗
(boolean indent)

Source from the content-addressed store, hash-verified

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) {

Callers 4

buildEditMenuMethod · 0.95
handleIndentMethod · 0.95
handleOutdentMethod · 0.95
TextAreaPopupMethod · 0.80

Calls 15

getIntegerMethod · 0.95
startCompoundEditMethod · 0.95
stopCompoundEditMethod · 0.95
getSelectionStartLineMethod · 0.80
getSelectionStopLineMethod · 0.80
selectMethod · 0.80
getDocumentLengthMethod · 0.80
getLineStartOffsetMethod · 0.45
getSelectionStopMethod · 0.45
isSelectionActiveMethod · 0.45
setSelectedTextMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected