Ticket #23477: 23477.patch

File 23477.patch, 3.3 KB (added by GerdP, 2 years ago)
  • src/org/openstreetmap/josm/actions/mapmode/ExtrudeAction.java

     
    3838import org.openstreetmap.josm.data.UndoRedoHandler;
    3939import org.openstreetmap.josm.data.coor.EastNorth;
    4040import org.openstreetmap.josm.data.coor.ILatLon;
    41 import org.openstreetmap.josm.data.osm.DataIntegrityProblemException;
    4241import org.openstreetmap.josm.data.osm.DataSet;
    4342import org.openstreetmap.josm.data.osm.Node;
    4443import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    8180    private long mouseDownTime;
    8281    private transient WaySegment selectedSegment;
    8382    private transient Node selectedNode;
     83    private transient Command lastCommandOnUndoStack;
    8484    private Color mainColor;
    8585    private transient Stroke mainStroke;
    8686
     
    331331        map.keyDetector.removeModifierExListener(this);
    332332        this.selectedNode = null;
    333333        this.selectedSegment = null;
     334        this.lastCommandOnUndoStack = null;
    334335        super.exitMode();
    335336    }
    336337
     
    401402
    402403        // If nothing gets caught, stay in select mode
    403404        if (selectedSegment == null && selectedNode == null) return;
     405        lastCommandOnUndoStack = UndoRedoHandler.getInstance().getLastCommand();
    404406
    405407        if (selectedNode != null) {
    406408            if (ctrl || nodeDragWithoutCtrl) {
     
    545547                    // double click adds a new node
    546548                    addNewNode(e);
    547549                } else if (e.getPoint().distance(initialMousePos) > initialMoveThreshold && newN1en != null && selectedSegment != null) {
    548                     try {
    549                         // main extrusion commands
    550                         performExtrusion();
    551                     } catch (DataIntegrityProblemException ex) {
    552                         // Can occur if calling undo while extruding, see #12870
    553                         Logging.error(ex);
    554                     }
     550                    // main extrusion commands
     551                    performExtrusion();
    555552                }
    556553            } else if (mode == Mode.translate || mode == Mode.translate_node) {
    557554                //Commit translate
     
    566563            mapView.setNewCursor(ctrl ? cursorTranslate : alt ? cursorCreateNew : shift ? cursorCreateNodes : cursor, this);
    567564            mapView.removeTemporaryLayer(this);
    568565            selectedSegment = null;
     566            lastCommandOnUndoStack = null;
    569567            moveCommand = null;
    570568            mode = Mode.select;
    571569            dualAlignSegmentCollapsed = false;
     
    638636     * Uses {@link #newN1en}, {@link #newN2en} calculated by {@link #calculateBestMovementAndNewNodes}
    639637     */
    640638    private void performExtrusion() {
     639        // sanity checks, see #23447 and #12870: don't try to extrude when user press undo
     640        if (lastCommandOnUndoStack != UndoRedoHandler.getInstance().getLastCommand())
     641            return;
    641642        DataSet ds = getLayerManager().getEditDataSet();
     643        if (ds.getPrimitiveById(selectedSegment.getWay()) == null || !selectedSegment.isUsable())
     644            return;
     645
    642646        // create extrusion
    643647        Collection<Command> cmds = new LinkedList<>();
    644648        Way wnew = new Way(selectedSegment.getWay());