This is an automated email from the ASF dual-hosted git repository.
lkishalmi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
The following commit(s) were added to refs/heads/master by this push:
new c825af0 [NETBEANS-403] Avoid scrolling to end of file if End is
pressed while popup is open. (#507)
c825af0 is described below
commit c825af0323e47eea429bde2de543bf07d863a42b
Author: Eirik Bakke <[email protected]>
AuthorDate: Sun Sep 30 20:40:47 2018 -0400
[NETBEANS-403] Avoid scrolling to end of file if End is pressed while popup
is open. (#507)
* [NETBEANS-403] Avoid scrolling to end of file if End is pressed while
popup is open.
* Revert the previous commit in preparation for taking a more conservative
approach, as requested in the pull request comments.
This reverts commit d55a6bae1158692607adf9e742e1f5a160c8accc.
* [NETBEANS-403] Avoid scrolling to end of file if End is pressed while
popup is open (more conservative approach).
---
.../src/org/netbeans/editor/PopupManager.java | 38 +++++++++++++++++-----
.../org/netbeans/editor/ext/ToolTipSupport.java | 10 ++++++
2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/ide/editor.lib/src/org/netbeans/editor/PopupManager.java
b/ide/editor.lib/src/org/netbeans/editor/PopupManager.java
index 92f3865..d428465 100644
--- a/ide/editor.lib/src/org/netbeans/editor/PopupManager.java
+++ b/ide/editor.lib/src/org/netbeans/editor/PopupManager.java
@@ -55,6 +55,16 @@ import org.openide.util.Parameters;
public class PopupManager {
private static final Logger LOG =
Logger.getLogger(PopupManager.class.getName());
+ /**
+ * Key for a boolean client property that can be set on the popup
component to suppress the
+ * forwarding of keyboard events into it. Note that popup keyboard actions
will still work if
+ * the popup receives explicit focus. See NETBEANS-403 and the associated
+ * <a href="https://github.com/apache/incubator-netbeans/pull/507">pull
request</a> (click
+ * "show outdated" to see the original pull request discussion). Make this
property private for
+ * now to avoid committing to an official API.
+ */
+ private static final String
SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY =
+ "suppress-popup-keyboard-forwarding";
private JComponent popup = null;
private final JTextComponent textComponent;
@@ -466,6 +476,18 @@ public class PopupManager {
consumeIfKeyPressInActionMap(e);
}
}
+
+ private boolean shouldPopupReceiveForwardedKeyboardAction(Object
actionKey) {
+ /* In NetBeans 8.2, the behavior was to forward all action events
except those whose key
+ was "tooltip-no-action" (which, reading through ToolTipSupport, I
think applies only to
+ the default action). To avoid breaking anything, keep this behavior
except when
+ SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY property has
been explicitly
+ set. The latter is used to fix NETBEANS-403. */
+ if (actionKey == null || actionKey.equals("tooltip-no-action"))
+ return false;
+ return popup == null || !Boolean.TRUE.equals(
+
popup.getClientProperty(SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY));
+ }
public @Override void keyPressed(KeyEvent e){
if (e != null && popup != null && popup.isShowing()) {
@@ -478,17 +500,18 @@ public class PopupManager {
KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
Object obj = im.get(ks);
LOG.log(Level.FINE, "Keystroke for event {0}: {1};
action-map-key={2}", new Object [] { e, ks, obj }); //NOI18N
- if (obj != null && !obj.equals("tooltip-no-action") //NOI18N
ignore ToolTipSupport installed actions
- ) {
+ if (shouldPopupReceiveForwardedKeyboardAction(obj)) {
// if yes, gets the popup's action for this keystroke,
perform it
// and consume key event
Action action = am.get(obj);
LOG.log(Level.FINE, "Popup component''s action: {0}, {1}",
new Object [] { action, action != null ? action.getValue(Action.NAME) : null
}); //NOI18N
- if (action != null && action.isEnabled()) {
- action.actionPerformed(null);
- e.consume();
- return;
+ /* Make sure to use the popup as the source of the action,
since the popup is
+ also providing the event. Not doing this, and instead
invoking actionPerformed
+ with a null ActionEvent, was one part of the problem seen
in NETBEANS-403. */
+ if (SwingUtilities.notifyAction(action, ks, e, popup,
e.getModifiers())) {
+ e.consume();
+ return;
}
}
@@ -521,8 +544,7 @@ public class PopupManager {
e.getKeyLocation())
);
Object obj = im.get(ks);
- if (obj != null && !obj.equals("tooltip-no-action") //NOI18N
ignore ToolTipSupport installed actions
- ) {
+ if (shouldPopupReceiveForwardedKeyboardAction(obj)) {
// if yes, if there is a popup's action, consume key event
Action action = am.get(obj);
if (action != null && action.isEnabled()) {
diff --git a/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
b/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
index 50c6e56..ef64103 100644
--- a/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
+++ b/ide/editor.lib/src/org/netbeans/editor/ext/ToolTipSupport.java
@@ -88,6 +88,10 @@ import org.openide.modules.PatchedPublic;
* @since 2.4
*/
public class ToolTipSupport {
+ /* From
PopupManager.SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY. (For
private use in
+ this module only. */
+ private static final String
SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY =
+ "suppress-popup-keyboard-forwarding";
// -J-Dorg.netbeans.editor.ext.ToolTipSupport.level=FINE
private static final Logger LOG =
Logger.getLogger(ToolTipSupport.class.getName());
@@ -384,6 +388,9 @@ public class ToolTipSupport {
}
JEditorPane tt = new HtmlTextToolTip();
+ /* See NETBEANS-403. It still appears possible to use Escape to close
the popup when the
+ focus is in the editor. */
+
tt.putClientProperty(SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY,
true);
// setup tooltip keybindings
filterBindings(tt.getActionMap());
@@ -469,6 +476,9 @@ public class ToolTipSupport {
}
JTextArea tt = new TextToolTip();
+ /* See NETBEANS-403. It still appears possible to use Escape to close
the popup when the
+ focus is in the editor. */
+
tt.putClientProperty(SUPPRESS_POPUP_KEYBOARD_FORWARDING_CLIENT_PROPERTY_KEY,
true);
// set up tooltip keybindings
filterBindings(tt.getActionMap());
---------------------------------------------------------------------
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