This is an automated email from the ASF dual-hosted git repository.
tmysik pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new ac131652d9 Avoid being scrolled to the end of the editor in the
preview panel for formatting options
new 18db5e3f37 Merge pull request #5759 from
junichi11/php-avoid-being-scrolled-to-eof-in-preview-panel
ac131652d9 is described below
commit ac131652d935c611036f4b9766e6ff31d1648e00
Author: Junichi Yamamoto <[email protected]>
AuthorDate: Sat Apr 1 13:24:27 2023 +0900
Avoid being scrolled to the end of the editor in the preview panel for
formatting options
- Currently, when the values of the formatting options are changed, the
preview panel is scrolled to the end of the editor
- To avoid it, keep the caret position before reformatting
---
.../src/org/netbeans/modules/php/editor/indent/FmtOptions.java | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git
a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java
b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java
index 63fa8aa45e..0a3fae7ad1 100644
--- a/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java
+++ b/php/php.editor/src/org/netbeans/modules/php/editor/indent/FmtOptions.java
@@ -44,6 +44,7 @@ import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
+import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
@@ -543,6 +544,10 @@ public final class FmtOptions {
// Ignore it
}
+ // keep the caret position
+ // to avoid being scrolled to the end of the editor
+ int caretPosition = pane.getCaretPosition();
+
Rectangle visibleRectangle = pane.getVisibleRect();
pane.setText(previewText);
pane.setIgnoreRepaint(true);
@@ -569,8 +574,10 @@ public final class FmtOptions {
} else {
LOGGER.warning(String.format("Can't format %s; it's not
BaseDocument.", doc)); //NOI18N
}
+ pane.setCaretPosition(caretPosition);
pane.setIgnoreRepaint(false);
- pane.scrollRectToVisible(visibleRectangle);
+ // invoke later because the preview pane is scrolled to the caret
position when we change options after we scroll it anywhere
+ SwingUtilities.invokeLater(() ->
pane.scrollRectToVisible(visibleRectangle));
pane.repaint(100);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists