From ede21ed6ae2ffb8150572170a6192f924dd587ff Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 4 Nov 2022 00:26:30 +0000 Subject: [PATCH] Handle string escaping for Find/Replace in labels. Fixes https://gitlab.com/kicad/code/kicad/issues/12789 (cherry picked from commit ae9405a4d35e4bd6574d2a0cc08a79bccd236325) --- eeschema/sch_text.cpp | 20 ++++++++++++++++++++ eeschema/sch_text.h | 11 ++--------- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/eeschema/sch_text.cpp b/eeschema/sch_text.cpp index ac356d61a8..4853df2a60 100644 --- a/eeschema/sch_text.cpp +++ b/eeschema/sch_text.cpp @@ -665,6 +665,26 @@ wxString SCH_TEXT::GetShownText( int aDepth, bool aAllowExtraText ) const } +bool SCH_TEXT::Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const +{ + return SCH_ITEM::Matches( UnescapeString( GetText() ), aSearchData ); +} + + +bool SCH_TEXT::Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) +{ + wxFindReplaceData localSearchData( aSearchData ); + + if( Type() == SCH_LABEL_T || Type() == SCH_HIER_LABEL_T || Type() == SCH_GLOBAL_LABEL_T ) + { + localSearchData.SetFindString( EscapeString( aSearchData.GetFindString(), CTX_NETNAME ) ); + localSearchData.SetReplaceString( EscapeString( aSearchData.GetReplaceString(), CTX_NETNAME ) ); + } + + return EDA_TEXT::Replace( localSearchData ); +} + + wxString SCH_TEXT::GetSelectMenuText( EDA_UNITS aUnits ) const { return wxString::Format( _( "Graphic Text '%s'" ), ShortenedShownText() ); diff --git a/eeschema/sch_text.h b/eeschema/sch_text.h index 00c7c4208d..c38421af4a 100644 --- a/eeschema/sch_text.h +++ b/eeschema/sch_text.h @@ -210,15 +210,8 @@ public: virtual void Rotate90( bool aClockwise ); virtual void MirrorSpinStyle( bool aLeftRight ); - bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override - { - return SCH_ITEM::Matches( GetText(), aSearchData ); - } - - bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override - { - return EDA_TEXT::Replace( aSearchData ); - } + bool Matches( const wxFindReplaceData& aSearchData, void* aAuxData ) const override; + bool Replace( const wxFindReplaceData& aSearchData, void* aAuxData ) override; virtual bool IsReplaceable() const override { return true; }