diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index bcb7a6fe9e..1ef5fdf4a3 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -22,6 +22,7 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ +#include #include #include #include @@ -283,7 +284,13 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) } if( status == UNDO_REDO::NEWITEM ) { - // new items are deleted on undo + // If we are removing the current sheet, get out first + if( SCH_SHEET* sheet = dyn_cast( eda_item ) ) + { + if( sheet->GetScreen() == GetScreen() ) + GetToolManager()->RunAction( EE_ACTIONS::leaveSheet ); + } + RemoveFromScreen( eda_item, screen ); aList->SetPickedItemStatus( UNDO_REDO::DELETED, ii ); }