From 629155bbc74a27d7c20e3aefa1f0a3defc34a6e2 Mon Sep 17 00:00:00 2001 From: Seth Hillbrand Date: Sun, 21 Sep 2025 14:06:52 -0700 Subject: [PATCH] Do not update value when selecting We are meant to update only the temparary value not the symbol actual Fixes https://gitlab.com/kicad/code/kicad/issues/21776 --- eeschema/sch_reference_list.cpp | 8 +++--- qa/tests/eeschema/test_sch_reference_list.cpp | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/eeschema/sch_reference_list.cpp b/eeschema/sch_reference_list.cpp index fd2a582c96..45811cb09d 100644 --- a/eeschema/sch_reference_list.cpp +++ b/eeschema/sch_reference_list.cpp @@ -771,10 +771,12 @@ SCH_REFERENCE::SCH_REFERENCE( SCH_SYMBOL* aSymbol, const SCH_SHEET_PATH& aSheetP m_numRef = -1; - if( aSymbol->GetValue( false, &aSheetPath, false ).IsEmpty() ) - aSymbol->SetValueFieldText( wxT( "~" ) ); + wxString value = aSymbol->GetValue( false, &aSheetPath, false ); - m_value = aSymbol->GetValue( false, &aSheetPath, false ); + if( value.IsEmpty() ) + value = wxT( "~" ); + + m_value = value; } diff --git a/qa/tests/eeschema/test_sch_reference_list.cpp b/qa/tests/eeschema/test_sch_reference_list.cpp index 6aac1dea3b..4701b1649f 100644 --- a/qa/tests/eeschema/test_sch_reference_list.cpp +++ b/qa/tests/eeschema/test_sch_reference_list.cpp @@ -297,4 +297,31 @@ BOOST_AUTO_TEST_CASE( ReannotateDuplicates ) } +BOOST_AUTO_TEST_CASE( ReferenceListDoesNotMutateEmptyValue ) +{ + loadTestCase( "test_multiunit_reannotate", {} ); + + SCH_SHEET_PATH sheetPath = m_schematic->CurrentSheet(); + SCH_SYMBOL* symbol = nullptr; + + for( SCH_ITEM* item : sheetPath.LastScreen()->Items().OfType( SCH_SYMBOL_T ) ) + { + symbol = static_cast( item ); + break; + } + + BOOST_REQUIRE( symbol != nullptr ); + + symbol->SetValueFieldText( wxEmptyString ); + BOOST_REQUIRE( symbol->GetValue( false, &sheetPath, false ).IsEmpty() ); + + SCH_REFERENCE_LIST refs; + sheetPath.AppendSymbol( refs, symbol ); + + BOOST_CHECK( symbol->GetValue( false, &sheetPath, false ).IsEmpty() ); + BOOST_REQUIRE_EQUAL( refs.GetCount(), 1 ); + BOOST_CHECK_EQUAL( refs[0].GetValue(), wxT( "~" ) ); +} + + BOOST_AUTO_TEST_SUITE_END()