From 40d7940d52b0538b6e19d201fdf2d7623e902826 Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Wed, 26 Aug 2020 00:02:11 +0100 Subject: [PATCH] Don't trim both back and front if there's only one char. Fixes https://gitlab.com/kicad/code/kicad/issues/5357 --- common/common.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/common/common.cpp b/common/common.cpp index 2f9ce89b6b..8a5023a4b2 100644 --- a/common/common.cpp +++ b/common/common.cpp @@ -323,11 +323,13 @@ void SelectReferenceNumber( wxTextEntry* aTextEntry ) while( !num.IsEmpty() && ( !isdigit( num.Last() ) || !isdigit( num.GetChar( 0 ) ) ) ) { + // Trim non-digit from end if( !isdigit( num.Last() ) ) num.RemoveLast(); - if( !isdigit( num.GetChar ( 0 ) ) ) - num = num.Right( num.Length() - 1); + // Trim non-digit from the start + if( !num.IsEmpty() && !isdigit( num.GetChar( 0 ) ) ) + num = num.Right( num.Length() - 1 ); } aTextEntry->SetSelection( ref.Find( num ), ref.Find( num ) + num.Length() );