Ticket #25012: 25012.patch

File 25012.patch, 3.4 KB (added by wangi, 2 weeks ago)
  • src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java

    diff --git src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java src/org/openstreetmap/josm/actions/mapmode/ParallelWayAction.java
    index 3715aca227..a0533459ab 100644
    public class ParallelWayAction extends MapMode implements ModifierExListener {  
    281281        if (e.getButton() != MouseEvent.BUTTON1)
    282282            return;
    283283
     284        // #25012: the release ending the previous drag never arrived (e.g. the focus moved to another application
     285        // during the drag), so nothing was committed - drop that drag and start afresh
     286        if (mode == Mode.DRAGGING) {
     287            pWays = null;
     288            setMode(Mode.NORMAL);
     289            resetMouseTrackingState();
     290            temporaryLayer.invalidate();
     291        }
     292
    284293        if (!sanityCheck())
    285294            return;
    286295
  • test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java

    diff --git test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java test/unit/org/openstreetmap/josm/actions/mapmode/ParallelWayActionTest.java
    index 7159008da9..1c01a96b9c 100644
    package org.openstreetmap.josm.actions.mapmode;  
    44import static org.junit.jupiter.api.Assertions.assertEquals;
    55import static org.junit.jupiter.api.Assertions.assertTrue;
    66
     7import org.awaitility.Awaitility;
     8import org.awaitility.Durations;
    79import org.junit.jupiter.api.BeforeEach;
    810import org.junit.jupiter.api.Test;
    911import org.openstreetmap.josm.TestUtils;
    … … class ParallelWayActionTest {  
    128130        assertEquals(5, this.dataSet.getWays().size(), this.dataSet.getWays().toString());
    129131    }
    130132
     133    /**
     134     * A drag whose mouse release was lost is dropped by the next press, which then starts a new drag.
     135     * <p>
     136     * Non-regression test for <a href="https://josm.openstreetmap.de/ticket/25012">#25012</a>: the press cleared the
     137     * offset path but left the mode at dragging, so the next drag event threw a {@link NullPointerException}.
     138     */
     139    @Test
     140    void testNonRegression25012() {
     141        Node a = new Node(LatLon.ZERO);
     142        Node b = new Node(new LatLon(0, 0.0001));
     143        Way w = new Way();
     144        w.addNode(a);
     145        w.addNode(b);
     146        this.dataSet.addPrimitive(a);
     147        this.dataSet.addPrimitive(b);
     148        this.dataSet.addPrimitive(w);
     149        this.map.selectMapMode(mapMode);
     150
     151        // a drag whose release never arrives, e.g. because the focus moved to another application
     152        mapMode.mousePressed(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005)));
     153        Awaitility.await().pollDelay(Durations.FIVE_HUNDRED_MILLISECONDS).until(() -> true);
     154        mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0, 0.00005)));
     155        mapMode.mouseDragged(MapModeUtils.mouseClickAt(new LatLon(0.00005, 0.00005)));
     156        assertEquals(3, this.dataSet.allPrimitives().size(), "nothing is created before the release");
     157
     158        MapModeUtils.dragFromTo(new LatLon(0, 0.00005), new LatLon(-0.00005, 0.00005));
     159        assertEquals(2, this.dataSet.getWays().size(), this.dataSet.getWays().toString());
     160        assertEquals(6, this.dataSet.allPrimitives().size());
     161    }
     162
    131163    /**
    132164     * Unit test of {@link Mode} enum.
    133165     */