From 40777d18ce21b573107bb1d6d73ee01ff1937f4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Tue, 19 Mar 2024 11:04:04 -0300 Subject: [PATCH] Fix in longest line width calculation. --- src/eepp/ui/uicodeeditor.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index f377d1e52..0c72ba71e 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -1556,8 +1556,8 @@ void UICodeEditor::onPaddingChange() { std::pair UICodeEditor::findLongestLineInRange( const TextRange& range ) { std::pair curRange{ mLongestLineIndex, mLongestLineWidth }; - Float longestLineWidth = mLongestLineWidth; if ( mHorizontalScrollBarEnabled ) { + Float longestLineWidth = 0; for ( Int64 lineIndex = range.start().line(); lineIndex <= range.end().line(); lineIndex++ ) { Float lineWidth = getLineWidth( lineIndex ); @@ -1718,9 +1718,15 @@ void UICodeEditor::onDocumentTextChanged( const DocumentContentChange& change ) checkMatchingBrackets(); sendCommonEvent( Event::OnTextChanged ); - auto range = findLongestLineInRange( change.range ); - mLongestLineIndex = range.first; - mLongestLineWidth = range.second; + if ( !change.text.empty() ) { + auto range = findLongestLineInRange( change.range ); + if ( range.second > mLongestLineWidth ) { + mLongestLineIndex = range.first; + mLongestLineWidth = range.second; + } + } else { + invalidateLongestLineWidth(); + } } void UICodeEditor::onDocumentCursorChange( const Doc::TextPosition& ) {