From f89803eb640c806489b5f23246245cf2ae49601e Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 13 Oct 2023 19:07:33 +0100 Subject: [PATCH] Don't turn an empty string into a '0'. Fixes https://gitlab.com/kicad/code/kicad/-/issues/15871 (cherry picked from commit 0b06a1376b5bc06cf2f97c6d7d476b221a5e85e7) --- eeschema/sim/sim_property.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/eeschema/sim/sim_property.cpp b/eeschema/sim/sim_property.cpp index f3e9324776..1c6467a505 100644 --- a/eeschema/sim/sim_property.cpp +++ b/eeschema/sim/sim_property.cpp @@ -92,29 +92,32 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima { wxTextEntry* textEntry = dynamic_cast( wnd_primary ); - if( textEntry ) + wxCHECK( textEntry, false ); + + wxString oldStr = m_eval.OriginalText(); + + if( oldStr.length() && oldStr != textEntry->GetValue() ) { - wxString oldStr = m_eval.OriginalText(); - - if( oldStr.length() && oldStr != textEntry->GetValue() ) - { - SetValueInEvent( oldStr ); - textEntry->SetValue( oldStr ); - } - - m_needsEval = true; - return true; + SetValueInEvent( oldStr ); + textEntry->SetValue( oldStr ); } + + m_needsEval = true; + return true; } else if( event.GetEventType() == wxEVT_KILL_FOCUS && allowEval() ) { wxTextEntry* textEntry = dynamic_cast( wnd_primary ); - if( textEntry && m_eval.Process( textEntry->GetValue() ) ) + wxCHECK( textEntry, false ); + + wxString strValue = textEntry->GetValue(); + + if( !strValue.IsEmpty() && m_eval.Process( strValue ) ) { double value = SIM_VALUE::ToDouble( m_eval.Result().ToStdString() ); - if( isnan( value ) || SIM_VALUE::Equal( value, textEntry->GetValue().ToStdString() ) ) + if( std::isnan( value ) || SIM_VALUE::Equal( value, strValue.ToStdString() ) ) { // Don't mess up user formatting if eval'ing didn't actually change the value. } @@ -122,10 +125,10 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima { SetValueInEvent( m_eval.Result() ); } - - m_needsEval = false; - return true; } + + m_needsEval = false; + return true; } else if( event.GetEventType() == wxEVT_KEY_DOWN ) {