From 052f4610ee2bde86002df946677b6801adba16cf Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 10 Nov 2022 09:05:34 +0800 Subject: [PATCH] - fix: crash when alt+mouse drag selection --- NEWS.md | 1 + RedPandaIDE/compiler/compilermanager.cpp | 7 ++++- RedPandaIDE/compiler/compilermanager.h | 6 +++++ RedPandaIDE/debugger.cpp | 4 +++ RedPandaIDE/debugger.h | 4 +++ RedPandaIDE/editor.cpp | 13 ++++++--- RedPandaIDE/parser/cppparser.cpp | 4 +++ RedPandaIDE/parser/cppparser.h | 4 +++ RedPandaIDE/todoparser.cpp | 4 +++ RedPandaIDE/todoparser.h | 4 +++ RedPandaIDE/widgets/classbrowser.cpp | 4 +++ RedPandaIDE/widgets/classbrowser.h | 4 +++ RedPandaIDE/widgets/codecompletionpopup.cpp | 4 +++ RedPandaIDE/widgets/codecompletionpopup.h | 10 +++++++ libs/qsynedit/qsynedit/SynEdit.cpp | 30 ++++++++++----------- libs/qsynedit/qsynedit/TextBuffer.cpp | 4 +++ libs/qsynedit/qsynedit/TextBuffer.h | 4 +++ 17 files changed, 91 insertions(+), 20 deletions(-) diff --git a/NEWS.md b/NEWS.md index ff2778c6..14e60beb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -13,6 +13,7 @@ Red Panda C++ Version 2.4 - fix: function pointers not correctly handle in code parser; - fix: var assignment not correctly handled in code parser; - fix: function args not correctly handled in code parser; + - fix: crash when alt+mouse drag selection Red Panda C++ Version 2.3 diff --git a/RedPandaIDE/compiler/compilermanager.cpp b/RedPandaIDE/compiler/compilermanager.cpp index 5c4d783b..e204b887 100644 --- a/RedPandaIDE/compiler/compilermanager.cpp +++ b/RedPandaIDE/compiler/compilermanager.cpp @@ -33,10 +33,15 @@ enum RunProgramFlag { }; CompilerManager::CompilerManager(QObject *parent) : QObject(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mCompileMutex(), + mBackgroundSyntaxCheckMutex(), + mRunnerMutex() +#else mCompileMutex(QMutex::Recursive), mBackgroundSyntaxCheckMutex(QMutex::Recursive), mRunnerMutex(QMutex::Recursive) - +#endif { mCompiler = nullptr; mBackgroundSyntaxChecker = nullptr; diff --git a/RedPandaIDE/compiler/compilermanager.h b/RedPandaIDE/compiler/compilermanager.h index 76e3f83e..7bd251c7 100644 --- a/RedPandaIDE/compiler/compilermanager.h +++ b/RedPandaIDE/compiler/compilermanager.h @@ -83,9 +83,15 @@ private: int mSyntaxCheckIssueCount; Compiler* mBackgroundSyntaxChecker; Runner* mRunner; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mCompileMutex; + QRecursiveMutex mBackgroundSyntaxCheckMutex; + QRecursiveMutex mRunnerMutex; +#else QMutex mCompileMutex; QMutex mBackgroundSyntaxCheckMutex; QMutex mRunnerMutex; +#endif }; class CompileError : public BaseError { diff --git a/RedPandaIDE/debugger.cpp b/RedPandaIDE/debugger.cpp index 4ef4f574..44fc77be 100644 --- a/RedPandaIDE/debugger.cpp +++ b/RedPandaIDE/debugger.cpp @@ -893,7 +893,11 @@ bool Debugger::executing() const } DebugReader::DebugReader(Debugger* debugger, QObject *parent) : QThread(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mCmdQueueMutex(), +#else mCmdQueueMutex(QMutex::Recursive), +#endif mStartSemaphore(0) { mDebugger = debugger; diff --git a/RedPandaIDE/debugger.h b/RedPandaIDE/debugger.h index 6f9bbcb1..98c3002c 100644 --- a/RedPandaIDE/debugger.h +++ b/RedPandaIDE/debugger.h @@ -559,7 +559,11 @@ private slots: private: Debugger *mDebugger; QString mDebuggerPath; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mCmdQueueMutex; +#else QMutex mCmdQueueMutex; +#endif QSemaphore mStartSemaphore; QQueue mCmdQueue; bool mErrorOccured; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8cd512f4..5e04bc7e 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -741,9 +741,16 @@ void Editor::keyPressEvent(QKeyEvent *event) handled=true; return; } + PStatement currentScope = mParser->findScopeStatement(mFilename,caretY()); + while(currentScope && currentScope->kind==StatementKind::skBlock) { + currentScope = currentScope->parentScope.lock(); + } + if (!currentScope || currentScope->kind == StatementKind::skNamespace) { + + return; + } + //last word is a type keyword, this is a var or param define, and dont show suggestion - // if devEditor.UseTabnine then - // ShowTabnineCompletion; return; } PStatement statement = mParser->findStatementOf( @@ -756,8 +763,6 @@ void Editor::keyPressEvent(QKeyEvent *event) || kind == StatementKind::skEnumType || kind == StatementKind::skTypedef) { //last word is a typedef/class/struct, this is a var or param define, and dont show suggestion - // if devEditor.UseTabnine then - // ShowTabnineCompletion; return; } } diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index 6e1c7386..c789bac9 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -28,7 +28,11 @@ static QAtomicInt cppParserCount(0); CppParser::CppParser(QObject *parent) : QObject(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mMutex() +#else mMutex(QMutex::Recursive) +#endif { mParserId = cppParserCount.fetchAndAddRelaxed(1); mLanguage = ParserLanguage::CPlusPlus; diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index 0c7a9a0e..f9fdea57 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -641,7 +641,11 @@ private: QHash mNamespaces; // namespace and the statements in its scope QSet mInlineNamespaces; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mMutex; +#else QMutex mMutex; +#endif GetFileStreamCallBack mOnGetFileStream; QMap mCppKeywords; QSet mCppTypeKeywords; diff --git a/RedPandaIDE/todoparser.cpp b/RedPandaIDE/todoparser.cpp index 90443bef..6e397d09 100644 --- a/RedPandaIDE/todoparser.cpp +++ b/RedPandaIDE/todoparser.cpp @@ -24,7 +24,11 @@ static QRegularExpression todoReg("\\b(todo|fixme)\\b", QRegularExpression::CaseInsensitiveOption); TodoParser::TodoParser(QObject *parent) : QObject(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mMutex() +#else mMutex(QMutex::Recursive) +#endif { mThread = nullptr; } diff --git a/RedPandaIDE/todoparser.h b/RedPandaIDE/todoparser.h index d44570a0..aab09e4f 100644 --- a/RedPandaIDE/todoparser.h +++ b/RedPandaIDE/todoparser.h @@ -100,7 +100,11 @@ public: private: TodoThread* mThread; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mMutex; +#else QMutex mMutex; +#endif }; using PTodoParser = std::shared_ptr; diff --git a/RedPandaIDE/widgets/classbrowser.cpp b/RedPandaIDE/widgets/classbrowser.cpp index 3bf68af6..29b2750a 100644 --- a/RedPandaIDE/widgets/classbrowser.cpp +++ b/RedPandaIDE/widgets/classbrowser.cpp @@ -26,7 +26,11 @@ #include "../iconsmanager.h" ClassBrowserModel::ClassBrowserModel(QObject *parent):QAbstractItemModel(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mMutex() +#else mMutex(QMutex::Recursive) +#endif { mClassBrowserType = ProjectClassBrowserType::CurrentFile; mRoot = new ClassBrowserNode(); diff --git a/RedPandaIDE/widgets/classbrowser.h b/RedPandaIDE/widgets/classbrowser.h index 429715e0..c42e037c 100644 --- a/RedPandaIDE/widgets/classbrowser.h +++ b/RedPandaIDE/widgets/classbrowser.h @@ -85,7 +85,11 @@ private: PCppParser mParser; bool mUpdating; int mUpdateCount; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mMutex; +#else QMutex mMutex; +#endif QString mCurrentFile; std::shared_ptr > > mColors; ProjectClassBrowserType mClassBrowserType; diff --git a/RedPandaIDE/widgets/codecompletionpopup.cpp b/RedPandaIDE/widgets/codecompletionpopup.cpp index 8b140a3f..2bb649b8 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.cpp +++ b/RedPandaIDE/widgets/codecompletionpopup.cpp @@ -31,7 +31,11 @@ CodeCompletionPopup::CodeCompletionPopup(QWidget *parent) : QWidget(parent), +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + mMutex() +#else mMutex(QMutex::Recursive) +#endif { setWindowFlags(Qt::Popup); mListView = new CodeCompletionListView(this); diff --git a/RedPandaIDE/widgets/codecompletionpopup.h b/RedPandaIDE/widgets/codecompletionpopup.h index 11abafce..38d232f5 100644 --- a/RedPandaIDE/widgets/codecompletionpopup.h +++ b/RedPandaIDE/widgets/codecompletionpopup.h @@ -37,6 +37,12 @@ private: const StatementList* mStatements; }; +enum class CodeCompletionType { + Normal, + ComplexType, + FunctionWithoutDefinition +}; + class CodeCompletionListItemDelegate: public QStyledItemDelegate { Q_OBJECT public: @@ -145,7 +151,11 @@ private: QSet mAddedStatements; QString mMemberPhrase; QString mMemberOperator; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mMutex; +#else QMutex mMutex; +#endif std::shared_ptr > > mColors; CodeCompletionListItemDelegate* mDelegate; diff --git a/libs/qsynedit/qsynedit/SynEdit.cpp b/libs/qsynedit/qsynedit/SynEdit.cpp index 87c681b6..319b5349 100644 --- a/libs/qsynedit/qsynedit/SynEdit.cpp +++ b/libs/qsynedit/qsynedit/SynEdit.cpp @@ -1957,23 +1957,23 @@ void SynEdit::doMouseScroll(bool isDragging) } BufferCoord vCaret = displayToBufferPos(C); if ((caretX() != vCaret.ch) || (caretY() != vCaret.line)) { - if (mActiveSelectionMode == SelectionMode::Column) { - int startLine=std::min(mBlockBegin.line,mBlockEnd.line); - startLine = std::min(startLine,vCaret.line); - int endLine=std::max(mBlockBegin.line,mBlockEnd.line); - endLine = std::max(endLine,vCaret.line); +// if (mActiveSelectionMode == SelectionMode::Column) { +// int startLine=std::min(mBlockBegin.line,mBlockEnd.line); +// startLine = std::min(startLine,vCaret.line); +// int endLine=std::max(mBlockBegin.line,mBlockEnd.line); +// endLine = std::max(endLine,vCaret.line); - int currentCol=displayXY().Column; - for (int i=startLine;i<=endLine;i++) { - QString s = mDocument->getString(i-1); - int cols = stringColumns(s,0); - if (cols+1getString(i-1); +// int cols = stringColumns(s,0); +// if (cols+1= QT_VERSION_CHECK(5, 15, 0) + mMutex() +#else mMutex(QMutex::Recursive) +#endif { mAppendNewLineAtEOF = true; diff --git a/libs/qsynedit/qsynedit/TextBuffer.h b/libs/qsynedit/qsynedit/TextBuffer.h index 8262de4b..05450437 100644 --- a/libs/qsynedit/qsynedit/TextBuffer.h +++ b/libs/qsynedit/qsynedit/TextBuffer.h @@ -146,7 +146,11 @@ private: bool mAppendNewLineAtEOF; int mIndexOfLongestLine; int mUpdateCount; +#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) + QRecursiveMutex mMutex; +#else QMutex mMutex; +#endif int calculateLineColumns(int Index); };