From c87750102f9530c887e86d3528948ffcefca9c1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 17 Jan 2024 00:26:32 -0300 Subject: [PATCH] macOS build fixes. UICodeEditor fix incorrect horizontal scroll when document is changed and fix incorrect horizontal scroll on document open. --- include/eepp/core/string.hpp | 3 +++ src/eepp/core/debug.cpp | 1 + src/eepp/ui/uicodeeditor.cpp | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/include/eepp/core/string.hpp b/include/eepp/core/string.hpp index 210fbd7e4..0701203ff 100644 --- a/include/eepp/core/string.hpp +++ b/include/eepp/core/string.hpp @@ -343,6 +343,8 @@ class EE_API String { template static std::string format( std::string_view format, Args&&... args ) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wformat-security" int size = std::snprintf( nullptr, 0, format.data(), FormatArg>::get( std::forward( args ) )... ) + @@ -353,6 +355,7 @@ class EE_API String { FormatArg>::get( std::forward( args ) )... ); result.resize( size - 1 ); } +#pragma clang diagnostic pop return result; } diff --git a/src/eepp/core/debug.cpp b/src/eepp/core/debug.cpp index 0b181e9d2..e54d4b023 100644 --- a/src/eepp/core/debug.cpp +++ b/src/eepp/core/debug.cpp @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index a3b2e9a0c..116a0b5d0 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -622,7 +622,7 @@ Float UICodeEditor::getViewportWidth( const bool& forceVScroll ) const { vScrollWidth += getMinimapWidth(); Float viewWidth = eefloor( mSize.getWidth() - mPaddingPx.Left - mPaddingPx.Right - getGutterWidth() - vScrollWidth ); - return viewWidth; + return eemax( 0.f, viewWidth ); } bool UICodeEditor::getShowIndentationGuides() const { @@ -856,6 +856,7 @@ void UICodeEditor::setDocument( std::shared_ptr doc ) { mDoc = doc; mDoc->registerClient( this ); invalidateEditor(); + invalidateLongestLineWidth(); invalidateDraw(); onDocumentChanged(); } @@ -1832,6 +1833,8 @@ void UICodeEditor::scrollTo( TextRange position, bool centered, bool forceExactP Float offsetXEnd = getXOffsetCol( position.end() ); Float minVisibility = getGlyphWidth(); Float viewPortWidth = getViewportWidth(); + if ( viewPortWidth == 0 ) + return; if ( offsetXEnd + minVisibility > mScroll.x + viewPortWidth ) { setScrollX( eefloor( eemax( 0.f, offsetXEnd + minVisibility - viewPortWidth ) ) ); } else if ( offsetXEnd < mScroll.x ) {