diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 3c56d554e..90b50b88b 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -1671,6 +1671,10 @@ public abstract class Editor extends JFrame implements RunnerListener { final String formattedText = createFormatter().format(source); // save current (rough) selection point int selectionEnd = getSelectionStop(); + +// boolean wasVisible = +// textarea.getSelectionStopLine() >= textarea.getFirstLine() && +// textarea.getSelectionStopLine() < textarea.getLastLine(); // make sure the caret would be past the end of the text if (formattedText.length() < selectionEnd - 1) { @@ -1682,8 +1686,24 @@ public abstract class Editor extends JFrame implements RunnerListener { } else { // replace with new bootiful text // selectionEnd hopefully at least in the neighborhood + int scrollPos = textarea.getScrollPosition(); setText(formattedText); setSelection(selectionEnd, selectionEnd); + + // Put the scrollbar position back, otherwise it jumps on each format. + // Since we're not doing a good job of maintaining position anyway, + // a more complicated workaround here is fairly pointless. + // http://code.google.com/p/processing/issues/detail?id=1533 + if (scrollPos != textarea.getScrollPosition()) { +// boolean wouldBeVisible = +// scrollPos >= textarea.getFirstLine() && +// scrollPos < textarea.getLastLine(); +// +// // if it was visible, and now it's not, then allow the scroll +// if (!(wasVisible && !wouldBeVisible)) { + textarea.setScrollPosition(scrollPos); +// } + } getSketch().setModified(true); // mark as finished statusNotice("Auto Format finished."); diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index e2821d08c..e7c91aa03 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -369,6 +369,14 @@ public class JEditTextArea extends JComponent painter.repaint(); } + + /** + * Convenience for checking what's on-screen. [fry] + */ + public final int getLastLine() { + return getFirstLine() + getVisibleLines(); + } + /** * Returns the number of lines visible in this text area. diff --git a/todo.txt b/todo.txt index c7dad8a7f..ef60fdab9 100644 --- a/todo.txt +++ b/todo.txt @@ -46,10 +46,14 @@ X http://code.google.com/p/processing/issues/detail?id=1520 X prevent inertia scrolling on OS X from making editor jumpy X Suggest possible import statements for common Java classes X http://code.google.com/p/processing/issues/detail?id=1550 +X for others like collections and Date, show warning and option to add? +X along with warning that it's not supported X processing-java throws java.lang.ArrayIndexOutOfBoundsException: -1 X http://code.google.com/p/processing/issues/detail?id=1548 X Library manager leaves temporary folders in sketchbook folder X http://code.google.com/p/processing/issues/detail?id=1527 +X "Auto format" should not scroll current line to first line +X http://code.google.com/p/processing/issues/detail?id=1533 manindra M bug that was causing the Debugger to point to wrong break point line numbers @@ -75,8 +79,6 @@ o if sketch was open, then restart by dragging the .pde to p5.app https://processing-js.lighthouseapp.com/ _ add Iterator as an import? -_ for others like collections and Date, show warning and option to add? -_ along with warning that it's not supported _ remove sketch.properties when moving back to the default? _ or can we not do this, because the next mode needs this?