Index: src/org/openstreetmap/josm/data/UndoRedoHandler.java
===================================================================
--- src/org/openstreetmap/josm/data/UndoRedoHandler.java	(revision 14674)
+++ src/org/openstreetmap/josm/data/UndoRedoHandler.java	(working copy)
@@ -1,6 +1,8 @@
 // License: GPL. For details, see LICENSE file.
 package org.openstreetmap.josm.data;
 
+import static org.openstreetmap.josm.tools.I18n.tr;
+
 import java.util.EventObject;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -7,9 +9,12 @@
 import java.util.List;
 import java.util.Objects;
 
+import javax.swing.JOptionPane;
+
 import org.openstreetmap.josm.command.Command;
 import org.openstreetmap.josm.data.osm.DataSet;
 import org.openstreetmap.josm.data.osm.OsmDataManager;
+import org.openstreetmap.josm.gui.Notification;
 import org.openstreetmap.josm.gui.util.GuiHelper;
 import org.openstreetmap.josm.spi.preferences.Config;
 import org.openstreetmap.josm.tools.CheckParameterUtil;
@@ -348,6 +353,7 @@
             return;
         GuiHelper.runInEDTAndWait(() -> {
             DataSet ds = OsmDataManager.getInstance().getEditDataSet();
+
             if (ds != null) {
                 ds.beginUpdate();
             }
@@ -354,6 +360,12 @@
             try {
                 for (int i = 1; i <= num; ++i) {
                     final Command c = commands.removeLast();
+                    if (c.getAffectedDataSet() != ds) {
+                        new Notification(tr("Cannot undo change in inactive data layer."))
+                                .setIcon(JOptionPane.WARNING_MESSAGE).setDuration(Notification.TIME_SHORT).show();
+                        commands.add(c);
+                        break;
+                    }
                     c.undoCommand();
                     redoCommands.addFirst(c);
                     fireEvent(new CommandUndoneEvent(this, c));
@@ -371,7 +383,7 @@
     }
 
     /**
-     * Redoes the last undoed command.
+     * Redoes the last undone command.
      */
     public void redo() {
         redo(1);
@@ -384,8 +396,16 @@
     public synchronized void redo(int num) {
         if (redoCommands.isEmpty())
             return;
+        DataSet ds = OsmDataManager.getInstance().getEditDataSet();
+
         for (int i = 0; i < num; ++i) {
             final Command c = redoCommands.removeFirst();
+            if (c.getAffectedDataSet() != ds) {
+                new Notification(tr("Cannot redo change in inactive data layer."))
+                        .setIcon(JOptionPane.INFORMATION_MESSAGE).setDuration(Notification.TIME_SHORT).show();
+                redoCommands.addFirst(c);
+                break;
+            }
             c.executeCommand();
             commands.add(c);
             fireEvent(new CommandRedoneEvent(this, c));
