Ignore:
Timestamp:
2020-10-18T13:24:50+02:00 (4 years ago)
Author:
Don-vip
Message:

fix #19120 - fix #19954 - Disable Shift shortcuts in text fields

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/widgets/DisableShortcutsOnFocusGainedTextField.java

    r12643 r17235  
    33
    44import java.awt.event.FocusEvent;
     5import java.awt.event.InputEvent;
    56import java.awt.event.KeyEvent;
    67import java.util.ArrayList;
     
    143144    protected void unregisterActionShortcuts() {
    144145        unregisteredActionShortcuts.clear();
    145         // Unregister all actions without modifiers to avoid them to be triggered by typing in this text field
     146        // Unregister all actions with Shift modifier or without modifiers to avoid them to be triggered by typing in this text field
    146147        for (Shortcut shortcut : Shortcut.listAll()) {
    147148            KeyStroke ks = shortcut.getKeyStroke();
     
    157158
    158159    /**
    159      * Returns true if the given shortcut has no modifier and is not an actions key.
     160     * Returns true if the given shortcut has Shift modifier or no modifier and is not an actions key.
    160161     * @param ks key stroke
    161162     * @return {@code true} if the given shortcut has to be disabled
     
    163164     */
    164165    protected boolean hasToBeDisabled(KeyStroke ks) {
    165         return ks != null && ks.getModifiers() == 0 && !new KeyEvent(
     166        return ks != null && (ks.getModifiers() == 0 || isOnlyShift(ks.getModifiers())) && !new KeyEvent(
    166167                this, KeyEvent.KEY_PRESSED, 0, ks.getModifiers(), ks.getKeyCode(), ks.getKeyChar()).isActionKey();
     168    }
     169
     170    private static boolean isOnlyShift(int modifiers) {
     171        return (modifiers & InputEvent.SHIFT_DOWN_MASK) != 0
     172                && (modifiers & InputEvent.CTRL_DOWN_MASK) == 0
     173                && (modifiers & InputEvent.ALT_DOWN_MASK) == 0
     174                && (modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) == 0
     175                && (modifiers & InputEvent.META_DOWN_MASK) == 0;
    167176    }
    168177
Note: See TracChangeset for help on using the changeset viewer.