Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 15063) +++ trunk/src/layer.c (revision 15064) @@ -454,7 +454,7 @@ int pcb_layer_move(pcb_board_t *pcb, pcb_layer_id_t old_index, pcb_layer_id_t new_index, pcb_layergrp_id_t new_in_grp) { - pcb_layer_id_t l; + pcb_layer_id_t l, at = -1; /* sanity checks */ if (old_index < -1 || old_index >= pcb->Data->LayerN) { @@ -477,8 +477,6 @@ return 1; } - pcb_undo_add_layer_move(old_index, new_index); - pcb_undo_inc_serial(); if (old_index == -1) { /* append new layer at the end of the logical layer list, put it in the current group */ pcb_layergrp_t *g; @@ -513,6 +511,7 @@ pcb_event(PCB_EVENT_LAYERS_CHANGED, NULL); pcb_layervis_change_group_vis(new_lid, 1, 1); pcb_event(PCB_EVENT_LAYERVIS_CHANGED, NULL); + at = new_lid; } else if (new_index == -1) { /* Delete the layer at old_index */ pcb_layergrp_id_t gid; @@ -569,6 +568,9 @@ layer list is insignificant, thus we shouldn't try to change it. */ } + pcb_undo_add_layer_move(old_index, new_index, at); + pcb_undo_inc_serial(); + return 0; } Index: trunk/src/undo_old.c =================================================================== --- trunk/src/undo_old.c (revision 15063) +++ trunk/src/undo_old.c (revision 15064) @@ -744,9 +744,21 @@ LayerChangeTypePtr l = &Entry->Data.LayerChange; int tmp; - tmp = l->new_index; - l->new_index = l->old_index; - l->old_index = tmp; + if (l->old_index == -1) { /* was creating new */ + l->old_index = l->at; + l->at = l->new_index; + l->new_index = -1; + } + else if (l->new_index == -1) { /* was deleting existing */ + l->new_index = l->at; + l->at = l->old_index; + l->old_index = -1; + } + else { + tmp = l->new_index; + l->new_index = l->old_index; + l->old_index = tmp; + } if (pcb_layer_move(PCB, l->old_index, l->new_index, -1)) return pcb_false; @@ -1295,7 +1307,7 @@ /* --------------------------------------------------------------------------- * adds a layer change (new, delete, move) to the undo list. */ -void pcb_undo_add_layer_move(int old_index, int new_index) +void pcb_undo_add_layer_move(int old_index, int new_index, int at) { UndoListTypePtr undo; @@ -1303,6 +1315,7 @@ undo = GetUndoSlot(PCB_UNDO_LAYERMOVE, 0, 0); undo->Data.LayerChange.old_index = old_index; undo->Data.LayerChange.new_index = new_index; + undo->Data.LayerChange.at = at; } } Index: trunk/src/undo_old.h =================================================================== --- trunk/src/undo_old.h (revision 15063) +++ trunk/src/undo_old.h (revision 15064) @@ -60,7 +60,7 @@ void pcb_undo_add_obj_to_change_angles(int, void *, void *, void *); void pcb_undo_add_obj_to_change_radii(int, void *, void *, void *); void pcb_undo_add_obj_to_clear_poly(int, void *, void *, void *, pcb_bool); -void pcb_undo_add_layer_move(int, int); +void pcb_undo_add_layer_move(int, int, int); void pcb_undo_add_netlist_lib(pcb_lib_t *); /* --------------------------------------------------------------------------- Index: trunk/src/undo_old_str.h =================================================================== --- trunk/src/undo_old_str.h (revision 15063) +++ trunk/src/undo_old_str.h (revision 15064) @@ -27,6 +27,7 @@ typedef struct { /* information about layer changes */ int old_index; int new_index; + int at; } LayerChangeType, *LayerChangeTypePtr; typedef struct { /* information about poly clear/restore */