Changeset 19454 in josm


Ignore:
Timestamp:
2026-01-05T14:23:41+01:00 (6 days ago)
Author:
stoecker
Message:

fix #24392 - patch by mattmccutchen - Typing plus or minus sign in Overpass query field no longer zooms the map

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapController.java

    r19050 r19454  
    22package org.openstreetmap.josm.gui.bbox;
    33
     4import java.awt.KeyboardFocusManager;
    45import java.awt.Point;
    56import java.awt.event.ActionEvent;
     
    1718import javax.swing.JPanel;
    1819import javax.swing.KeyStroke;
     20import javax.swing.text.JTextComponent;
    1921
    2022import org.openstreetmap.josm.tools.PlatformManager;
     
    9395        // zooming. To avoid confusion about which modifier key to use,
    9496        // we just add all keys left of the space bar
     97        //
     98        // Typing the '+', '=', or '-' character in the Overpass query field
     99        // seems to trigger these key bindings, which would zoom the map
     100        // (https://josm.openstreetmap.de/ticket/24392). To prevent that, those
     101        // keys use a special version of the action that does nothing if a text
     102        // field is focused. That feels like a hack, but we didn't find an
     103        // obvious better way.
    95104        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.CTRL_DOWN_MASK, false), "ZOOM_IN");
    96105        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.META_DOWN_MASK, false), "ZOOM_IN");
    97106        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, InputEvent.ALT_DOWN_MASK, false), "ZOOM_IN");
    98         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0, false), "ZOOM_IN");
    99         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0, false), "ZOOM_IN");
    100         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, 0, false), "ZOOM_IN");
    101         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.SHIFT_DOWN_MASK, false), "ZOOM_IN");
     107        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, 0, false), "ZOOM_IN_UNLESS_TYPING");
     108        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PLUS, 0, false), "ZOOM_IN_UNLESS_TYPING");
     109        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, 0, false), "ZOOM_IN_UNLESS_TYPING");
     110        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, InputEvent.SHIFT_DOWN_MASK, false), "ZOOM_IN_UNLESS_TYPING");
    102111        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_DOWN_MASK, false), "ZOOM_OUT");
    103112        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.META_DOWN_MASK, false), "ZOOM_OUT");
    104113        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.ALT_DOWN_MASK, false), "ZOOM_OUT");
    105         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0, false), "ZOOM_OUT");
    106         inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0, false), "ZOOM_OUT");
     114        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, 0, false), "ZOOM_OUT_UNLESS_TYPING");
     115        inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_MINUS, 0, false), "ZOOM_OUT_UNLESS_TYPING");
    107116
    108117        // action mapping
     
    113122        actionMap.put("STOP_MOVE_HORIZONTALLY", new MoveXAction(0));
    114123        actionMap.put("STOP_MOVE_VERTICALLY", new MoveYAction(0));
    115         actionMap.put("ZOOM_IN", new ZoomInAction());
    116         actionMap.put("ZOOM_OUT", new ZoomOutAction());
     124        actionMap.put("ZOOM_IN", new ZoomInAction(false));
     125        actionMap.put("ZOOM_IN_UNLESS_TYPING", new ZoomInAction(true));
     126        actionMap.put("ZOOM_OUT", new ZoomOutAction(false));
     127        actionMap.put("ZOOM_OUT_UNLESS_TYPING", new ZoomOutAction(true));
    117128    }
    118129
     
    301312    }
    302313
     314    static boolean isTyping() {
     315        return KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner() instanceof JTextComponent;
     316    }
     317
    303318    private final class ZoomInAction extends AbstractAction {
    304319
     320        private boolean suppressWhileTyping;
     321
     322        ZoomInAction(boolean suppressWhileTyping) {
     323            this.suppressWhileTyping = suppressWhileTyping;
     324        }
     325
    305326        @Override
    306327        public void actionPerformed(ActionEvent e) {
     328            if (suppressWhileTyping && isTyping())
     329                return;
    307330            iSlippyMapChooser.zoomIn();
    308331        }
     
    311334    private final class ZoomOutAction extends AbstractAction {
    312335
     336        private boolean suppressWhileTyping;
     337
     338        ZoomOutAction(boolean suppressWhileTyping) {
     339            this.suppressWhileTyping = suppressWhileTyping;
     340        }
     341
    313342        @Override
    314343        public void actionPerformed(ActionEvent e) {
     344            if (suppressWhileTyping && isTyping())
     345                return;
    315346            iSlippyMapChooser.zoomOut();
    316347        }
Note: See TracChangeset for help on using the changeset viewer.