mirror of
https://github.com/processing/processing4.git
synced 2026-01-28 02:41:08 +01:00
prevent auto format from scrolling (issue #1533)
This commit is contained in:
@@ -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.");
|
||||
|
||||
@@ -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.
|
||||
|
||||
6
todo.txt
6
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?
|
||||
|
||||
Reference in New Issue
Block a user