MCPcopy Index your code
hub / github.com/processing/processing / handleAutoFormat

Method handleAutoFormat

app/src/processing/app/ui/Editor.java:2062–2104  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2060
2061
2062 public void handleAutoFormat() {
2063 final String source = getText();
2064
2065 try {
2066 final String formattedText = createFormatter().format(source);
2067 // save current (rough) selection point
2068 int selectionEnd = getSelectionStop();
2069
2070// boolean wasVisible =
2071// textarea.getSelectionStopLine() >= textarea.getFirstLine() &&
2072// textarea.getSelectionStopLine() < textarea.getLastLine();
2073
2074 // make sure the caret would be past the end of the text
2075 if (formattedText.length() < selectionEnd - 1) {
2076 selectionEnd = formattedText.length() - 1;
2077 }
2078
2079 if (formattedText.equals(source)) {
2080 statusNotice(Language.text("editor.status.autoformat.no_changes"));
2081
2082 } else { // replace with new bootiful text
2083 startCompoundEdit();
2084 // selectionEnd hopefully at least in the neighborhood
2085 int scrollPos = textarea.getVerticalScrollPosition();
2086 textarea.setText(formattedText);
2087 setSelection(selectionEnd, selectionEnd);
2088
2089 // Put the scrollbar position back, otherwise it jumps on each format.
2090 // Since we're not doing a good job of maintaining position anyway,
2091 // a more complicated workaround here is fairly pointless.
2092 // http://code.google.com/p/processing/issues/detail?id=1533
2093 if (scrollPos != textarea.getVerticalScrollPosition()) {
2094 textarea.setVerticalScrollPosition(scrollPos);
2095 }
2096 stopCompoundEdit();
2097 sketch.setModified(true);
2098 statusNotice(Language.text("editor.status.autoformat.finished"));
2099 }
2100
2101 } catch (final Exception e) {
2102 statusError(e);
2103 }
2104 }
2105
2106
2107 abstract public String getCommentPrefix();

Callers 1

actionPerformedMethod · 0.95

Calls 15

getTextMethod · 0.95
createFormatterMethod · 0.95
getSelectionStopMethod · 0.95
statusNoticeMethod · 0.95
textMethod · 0.95
startCompoundEditMethod · 0.95
setSelectionMethod · 0.95
stopCompoundEditMethod · 0.95
statusErrorMethod · 0.95
formatMethod · 0.65

Tested by

no test coverage detected