diff --git a/src/tools/ecode/projectsearch.cpp b/src/tools/ecode/projectsearch.cpp index baa7f31f8..4526f2f83 100644 --- a/src/tools/ecode/projectsearch.cpp +++ b/src/tools/ecode/projectsearch.cpp @@ -28,8 +28,10 @@ static String textLine( const std::string& fileText, const size_t& fromPos, size if ( stringStartPtr != ptr ) { while ( stringStartPtr != ptr && *--ptr != '\n' ) { } - nlStartPtr = ptr + 1; - start = ptr - stringStartPtr + 1; + if ( stringStartPtr != ptr ) { + nlStartPtr = ptr + 1; + start = ptr - stringStartPtr + 1; + } } ptr = startPtr; while ( ++ptr && *ptr != '\0' && *ptr != '\n' ) { diff --git a/src/tools/ecode/uitreeviewglobalsearch.cpp b/src/tools/ecode/uitreeviewglobalsearch.cpp index 3f548627f..8090438ec 100644 --- a/src/tools/ecode/uitreeviewglobalsearch.cpp +++ b/src/tools/ecode/uitreeviewglobalsearch.cpp @@ -148,7 +148,7 @@ UIPushButton* UITreeViewCellGlobalSearch::updateText( const std::string& text ) const String& txt = mTextBox->getText(); - if ( mSearchStrPos.second < txt.size() ) { + if ( mSearchStrPos.second <= txt.size() ) { mResultStr = String( txt.toUtf8().substr( mSearchStrPos.first, mSearchStrPos.second - mSearchStrPos.first ) ); } else { @@ -191,28 +191,25 @@ static Float getXOffsetCol( Float glyphWidth, Uint32 tabWidth, const String& lin void UITreeViewCellGlobalSearch::draw() { UITreeViewCell::draw(); - if ( getCurIndex().internalId() != -1 ) { + if ( getCurIndex().internalId() != -1 && mSearchStrPos.first != std::string::npos && + mSearchStrPos.second > 0 && mSearchStrPos.second <= mTextBox->getText().length() ) { UITreeViewGlobalSearch* pp = getParent()->getParent()->asType(); - if ( mSearchStrPos.first != std::string::npos && mSearchStrPos.second > 0 ) { - auto hspace = - mTextBox->getFont()->getGlyph( L' ', mTextBox->getPixelsFontSize(), false ).advance; - Primitives p; - p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection" ).color ); - Vector2f screenPos( mScreenPos ); - if ( mTextBox->isType( UI_TYPE_CHECKBOX ) ) { - UICheckBox* chk = mTextBox->asType(); - screenPos.x += chk->getRealAlignOffset().x; - } - if ( mSearchStrPos.second >= mTextBox->getText().length() ) - return; - p.drawRectangle( Rectf( - { screenPos.x + mTextBox->getPixelsPosition().x + - getXOffsetCol( hspace, mTextBox->getTextCache()->getTabWidth(), - mTextBox->getText(), mSearchStrPos.first ), - screenPos.y + mTextBox->getPixelsPosition().y }, - Sizef( getTextWidth( hspace, mTextBox->getTextCache()->getTabWidth(), mResultStr ), - mTextBox->getPixelsSize().getHeight() ) ) ); + auto hspace = + mTextBox->getFont()->getGlyph( L' ', mTextBox->getPixelsFontSize(), false ).advance; + Primitives p; + p.setColor( pp->getColorScheme().getEditorSyntaxStyle( "selection" ).color ); + Vector2f screenPos( mScreenPos ); + if ( mTextBox->isType( UI_TYPE_CHECKBOX ) ) { + UICheckBox* chk = mTextBox->asType(); + screenPos.x += chk->getRealAlignOffset().x; } + p.drawRectangle( Rectf( + { screenPos.x + mTextBox->getPixelsPosition().x + + getXOffsetCol( hspace, mTextBox->getTextCache()->getTabWidth(), + mTextBox->getText(), mSearchStrPos.first ), + screenPos.y + mTextBox->getPixelsPosition().y }, + Sizef( getTextWidth( hspace, mTextBox->getTextCache()->getTabWidth(), mResultStr ), + mTextBox->getPixelsSize().getHeight() ) ) ); } }