From a447da4002eb4d474adf247043029620c86a2cda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sun, 29 Dec 2024 12:37:45 -0300 Subject: [PATCH] Fix crash when trying to highlight matching bracket where its line was hidden. --- src/eepp/ui/doc/documentview.cpp | 5 +++-- src/eepp/ui/uicodeeditor.cpp | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/eepp/ui/doc/documentview.cpp b/src/eepp/ui/doc/documentview.cpp index 6a382cdbc..a5c98aab7 100644 --- a/src/eepp/ui/doc/documentview.cpp +++ b/src/eepp/ui/doc/documentview.cpp @@ -341,8 +341,9 @@ DocumentView::VisibleLineRange DocumentView::getVisibleLineRange( const TextPosi } eeASSERT( toIdx >= 0 ); info.visibleIndex = static_cast( toIdx ); - info.range = { { pos.line(), mVisibleLines[toIdx].column() }, - mDoc->endOfLine( { pos.line(), 0ll } ) }; + if ( info.visibleIndex != VisibleIndex::invalid ) + info.range = { { pos.line(), mVisibleLines[toIdx].column() }, + mDoc->endOfLine( { pos.line(), 0ll } ) }; return info; } diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index df22fe039..ded330570 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2234,6 +2234,8 @@ Vector2d UICodeEditor::getTextPositionOffset( const TextPosition& position, : 0.f ); double offsetY = mDocView.getLineYOffset( info.visibleIndex, lh ); if ( isNotMonospace() ) { + if ( !info.range.isValid() ) + return {}; const auto& line = mDoc->line( position.line() ).getText(); auto partialLine = line.view().substr( info.range.start().column(), info.range.end().column() ); @@ -3379,6 +3381,9 @@ void UICodeEditor::drawMatchingBrackets( const Vector2f& startScroll, const Floa primitive.setForceDraw( false ); primitive.setColor( Color( mMatchingBracketColor ).blendAlpha( mAlpha ) ); auto drawBracket = [&]( const TextPosition& pos ) { + auto info = mDocView.getVisibleLineRange( pos ); + if ( !info.range.isValid() ) + return; auto offset = getTextPositionOffset( pos, lineHeight ); primitive.drawRectangle( Rectf( Vector2f( startScroll.x + offset.x, startScroll.y + offset.y ),