prevent auto format from scrolling (issue #1533)

This commit is contained in:
benfry
2013-01-21 19:57:14 +00:00
parent 105dc0e8f4
commit 82f1a0cae6
3 changed files with 32 additions and 2 deletions

View File

@@ -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.");

View File

@@ -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.

View File

@@ -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?