From cc165129fdd38bae82b94488324538d2542a6ab9 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sat, 19 Mar 2022 19:36:20 +0000 Subject: [PATCH] Special case undo for items with instance data. Fixes https://gitlab.com/kicad/code/kicad/issues/11102 --- eeschema/schematic_undo_redo.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/eeschema/schematic_undo_redo.cpp b/eeschema/schematic_undo_redo.cpp index a02bb7eb16..46b6f2c45d 100644 --- a/eeschema/schematic_undo_redo.cpp +++ b/eeschema/schematic_undo_redo.cpp @@ -324,6 +324,31 @@ void SCH_EDIT_FRAME::PutDataInPreviousState( PICKED_ITEMS_LIST* aList ) { case UNDO_REDO::CHANGED: item->SwapData( alt_item ); + + // Special cases for items which have instance data + if( item->GetParent() && item->GetParent()->Type() == SCH_SYMBOL_T + && item->Type() == SCH_FIELD_T ) + { + SCH_FIELD* field = static_cast( item ); + SCH_SYMBOL* symbol = static_cast( item->GetParent() ); + + if( field->GetId() == REFERENCE_FIELD ) + { + symbol->SetRef( m_schematic->GetSheets().FindSheetForScreen( screen ), + field->GetText() ); + } + else if( field->GetId() == VALUE_FIELD ) + { + symbol->SetValue( m_schematic->GetSheets().FindSheetForScreen( screen ), + field->GetText() ); + } + else if( field->GetId() == FOOTPRINT_FIELD ) + { + symbol->SetFootprint( m_schematic->GetSheets().FindSheetForScreen( screen ), + field->GetText() ); + } + } + break; case UNDO_REDO::EXCHANGE_T: