From 0fe59e3ca952e9eabcefd7dc2e27d9f2e9ee9827 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 3 Feb 2024 12:37:49 -0300 Subject: [PATCH] Fix automatic scrolling while writing in UITextEdit. Fix threadpool close. Git plugin safetly destruct. --- include/eepp/ui/uicodeeditor.hpp | 5 +++-- src/eepp/ui/uicodeeditor.cpp | 23 +++++++++++++---------- src/tools/ecode/ecode.cpp | 3 +++ src/tools/ecode/plugins/git/gitplugin.cpp | 5 +++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/include/eepp/ui/uicodeeditor.hpp b/include/eepp/ui/uicodeeditor.hpp index d9ee8edee..1bb90e7ca 100644 --- a/include/eepp/ui/uicodeeditor.hpp +++ b/include/eepp/ui/uicodeeditor.hpp @@ -701,7 +701,7 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { SyntaxColorScheme mColorScheme; UIScrollBar* mVScrollBar; UIScrollBar* mHScrollBar; - std::unordered_map mLastXOffset; + UnorderedMap mLastXOffset; KeyBindings mKeyBindings; std::unordered_set mUnlockedCmd; Clock mLastDoubleClick; @@ -728,7 +728,8 @@ class EE_API UICodeEditor : public UIWidget, public TextDocument::Client { Text text; String::HashType hash; }; - mutable std::unordered_map mTextCache; + mutable UnorderedMap mTextCache; + UnorderedMap> mLinesWidthCache; Tools::UIDocFindReplace* mFindReplace{ nullptr }; struct PluginRequestedSpace { UICodeEditorPlugin* plugin; diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 6f3da9f65..22c1dbcda 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -941,11 +941,10 @@ void UICodeEditor::updateIMELocation() { } void UICodeEditor::drawLockedIcon( const Vector2f start ) { - if ( mFileLockIcon == nullptr && !mFileLockIconName.empty() ) { + if ( mFileLockIcon == nullptr && !mFileLockIconName.empty() ) mFileLockIcon = getUISceneNode()->findIcon( mFileLockIconName ); - if ( mFileLockIcon == nullptr ) - return; - } + if ( mFileLockIcon == nullptr ) + return; Drawable* fileLockIcon = mFileLockIcon->getSize( PixelDensity::dpToPxI( 16 ) ); if ( fileLockIcon == nullptr ) @@ -1552,19 +1551,23 @@ void UICodeEditor::findLongestLine() { Float UICodeEditor::getLineWidth( const Int64& lineIndex ) { if ( lineIndex >= (Int64)mDoc->linesCount() ) return 0; - if ( mFont && !mFont->isMonospace() ) - return Text::getTextWidth( mFont, getCharacterSize(), mDoc->line( lineIndex ).getText(), - mFontStyleConfig.Style, mTabWidth ) + - getGlyphWidth(); + if ( mFont && !mFont->isMonospace() ) { + auto line = mDoc->line( lineIndex ); + auto found = mLinesWidthCache.find( lineIndex ); + if ( found != mLinesWidthCache.end() && line.getHash() == found->first ) + return found->second.second; + Float width = getTextWidth( line.getText() ) + getGlyphWidth(); + mLinesWidthCache[lineIndex] = { line.getHash(), width }; + return width; + } return getTextWidth( mDoc->line( lineIndex ).getText() ); } void UICodeEditor::updateScrollBar() { int notVisibleLineCount = (int)mDoc->linesCount() - (int)getViewPortLineCount().y; - if ( mLongestLineWidthDirty && mFont && mFont->isMonospace() ) { + if ( mLongestLineWidthDirty && mFont ) updateLongestLineWidth(); - } mHScrollBar->setEnabled( false ); mHScrollBar->setVisible( false ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 5e9d7f3db..1fa5e74e4 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -714,7 +714,10 @@ App::App( const size_t& jobs, const std::vector& args ) : App::~App() { if ( mProjectBuildManager ) mProjectBuildManager.reset(); + + Http::setThreadPool( nullptr ); mThreadPool.reset(); + if ( mFileWatcher ) { Lock l( mWatchesLock ); delete mFileWatcher; diff --git a/src/tools/ecode/plugins/git/gitplugin.cpp b/src/tools/ecode/plugins/git/gitplugin.cpp index e26cd814f..81dccc4fe 100644 --- a/src/tools/ecode/plugins/git/gitplugin.cpp +++ b/src/tools/ecode/plugins/git/gitplugin.cpp @@ -81,6 +81,11 @@ GitPlugin::~GitPlugin() { mStatusButton->close(); if ( mSidePanel && mTab ) mSidePanel->removeTab( mTab ); + + { Lock l( mGitBranchMutex ); } + { Lock l( mGitStatusMutex ); } + { Lock l( mRepoMutex ); } + { Lock l( mReposMutex ); } } void GitPlugin::load( PluginManager* pluginManager ) {