From ee724f6a2b3c91c37eae551f2f52fa4b94f4b910 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Tue, 12 Sep 2023 15:50:35 +0100 Subject: [PATCH] Only update value on rename if it previously matched the symbol name. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15621 --- eeschema/tools/symbol_editor_control.cpp | 30 +++++++++--------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/eeschema/tools/symbol_editor_control.cpp b/eeschema/tools/symbol_editor_control.cpp index 300b8520bd..309cfdc927 100644 --- a/eeschema/tools/symbol_editor_control.cpp +++ b/eeschema/tools/symbol_editor_control.cpp @@ -390,23 +390,25 @@ int SYMBOL_EDITOR_CONTROL::RenameSymbol( const TOOL_EVENT& aEvent ) wxString newName = dlg.GetSymbolName(); wxString oldName = symbolName; - LIB_SYMBOL* libSymbol = nullptr; + LIB_SYMBOL* libSymbol = libMgr.GetBufferedSymbol( oldName, libName ); + bool isCurrentSymbol = editFrame->IsCurrentSymbol( libId ); - if( editFrame->IsCurrentSymbol( libId ) ) - { - // Update buffered copy - libSymbol = libMgr.GetBufferedSymbol( oldName, libName ); + libSymbol->SetName( newName ); - libSymbol->SetName( newName ); + if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName ) libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName ); - libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName ); + libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName ); + libMgr.SetSymbolModified( newName, libName ); - // Now update canvasy copy + if( isCurrentSymbol ) + { libSymbol = editFrame->GetCurSymbol(); libSymbol->SetName( newName ); - libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName ); + + if( libSymbol->GetFieldById( VALUE_FIELD )->GetText() == oldName ) + libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName ); editFrame->RebuildView(); editFrame->OnModify(); @@ -415,16 +417,6 @@ int SYMBOL_EDITOR_CONTROL::RenameSymbol( const TOOL_EVENT& aEvent ) // invalidate the view pointers by rebuilting the field table editFrame->UpdateMsgPanel(); } - else - { - libSymbol = libMgr.GetBufferedSymbol( oldName, libName ); - - libSymbol->SetName( newName ); - libSymbol->GetFieldById( VALUE_FIELD )->SetText( newName ); - - libMgr.UpdateSymbolAfterRename( libSymbol, newName, libName ); - libMgr.SetSymbolModified( newName, libName ); - } wxDataViewItem treeItem = libMgr.GetAdapter()->FindItem( libId ); editFrame->UpdateLibraryTree( treeItem, libSymbol );