Don't turn an empty string into a '0'.

Fixes https://gitlab.com/kicad/code/kicad/-/issues/15871

(cherry picked from commit 0b06a1376b)
This commit is contained in:
Jeff Young 2023-10-13 19:07:33 +01:00
parent da12746a3a
commit f89803eb64
1 changed files with 19 additions and 16 deletions

View File

@ -92,29 +92,32 @@ bool SIM_STRING_PROPERTY::OnEvent( wxPropertyGrid* propgrid, wxWindow* wnd_prima
{ {
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wnd_primary ); wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wnd_primary );
if( textEntry ) wxCHECK( textEntry, false );
wxString oldStr = m_eval.OriginalText();
if( oldStr.length() && oldStr != textEntry->GetValue() )
{ {
wxString oldStr = m_eval.OriginalText(); SetValueInEvent( oldStr );
textEntry->SetValue( oldStr );
if( oldStr.length() && oldStr != textEntry->GetValue() )
{
SetValueInEvent( oldStr );
textEntry->SetValue( oldStr );
}
m_needsEval = true;
return true;
} }
m_needsEval = true;
return true;
} }
else if( event.GetEventType() == wxEVT_KILL_FOCUS && allowEval() ) else if( event.GetEventType() == wxEVT_KILL_FOCUS && allowEval() )
{ {
wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( wnd_primary ); wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( 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() ); 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. // 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() ); SetValueInEvent( m_eval.Result() );
} }
m_needsEval = false;
return true;
} }
m_needsEval = false;
return true;
} }
else if( event.GetEventType() == wxEVT_KEY_DOWN ) else if( event.GetEventType() == wxEVT_KEY_DOWN )
{ {