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

Method handleAutoFormat

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

Source from the content-addressed store, hash-verified

1713
1714
1715 public void handleAutoFormat() {
1716 final String source = getText();
1717
1718 try {
1719 final String formattedText = createFormatter().format(source);
1720 // save current (rough) selection point
1721 int selectionEnd = getSelectionStop();
1722
1723// boolean wasVisible =
1724// textarea.getSelectionStopLine() >= textarea.getFirstLine() &&
1725// textarea.getSelectionStopLine() < textarea.getLastLine();
1726
1727 // make sure the caret would be past the end of the text
1728 if (formattedText.length() < selectionEnd - 1) {
1729 selectionEnd = formattedText.length() - 1;
1730 }
1731
1732 if (formattedText.equals(source)) {
1733 statusNotice(Language.text("editor.status.autoformat.no_changes"));
1734
1735 } else { // replace with new bootiful text
1736 startCompoundEdit();
1737 // selectionEnd hopefully at least in the neighborhood
1738 int scrollPos = textarea.getVerticalScrollPosition();
1739 textarea.setText(formattedText);
1740 setSelection(selectionEnd, selectionEnd);
1741
1742 // Put the scrollbar position back, otherwise it jumps on each format.
1743 // Since we're not doing a good job of maintaining position anyway,
1744 // a more complicated workaround here is fairly pointless.
1745 // https://github.com/processing/processing/issues/1571
1746 if (scrollPos != textarea.getVerticalScrollPosition()) {
1747 textarea.setVerticalScrollPosition(scrollPos);
1748 }
1749 stopCompoundEdit();
1750 sketch.setModified(true);
1751 statusNotice(Language.text("editor.status.autoformat.finished"));
1752 }
1753
1754 } catch (final Exception e) {
1755 statusError(e);
1756 }
1757 }
1758
1759
1760 abstract public String getCommentPrefix();

Callers 1

buildEditMenuMethod · 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