- fix: crash when alt+mouse drag selection

This commit is contained in:
Roy Qu 2022-11-10 09:05:34 +08:00
parent ae7e914788
commit 052f4610ee
17 changed files with 91 additions and 20 deletions

View File

@ -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

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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<PDebugCommand> mCmdQueue;
bool mErrorOccured;

View File

@ -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;
}
}

View File

@ -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;

View File

@ -641,7 +641,11 @@ private:
QHash<QString,PStatementList> mNamespaces; // namespace and the statements in its scope
QSet<QString> mInlineNamespaces;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRecursiveMutex mMutex;
#else
QMutex mMutex;
#endif
GetFileStreamCallBack mOnGetFileStream;
QMap<QString,KeywordType> mCppKeywords;
QSet<QString> mCppTypeKeywords;

View File

@ -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;
}

View File

@ -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<TodoParser>;

View File

@ -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();

View File

@ -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<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mColors;
ProjectClassBrowserType mClassBrowserType;

View File

@ -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);

View File

@ -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<QString> mAddedStatements;
QString mMemberPhrase;
QString mMemberOperator;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRecursiveMutex mMutex;
#else
QMutex mMutex;
#endif
std::shared_ptr<QHash<StatementKind, std::shared_ptr<ColorSchemeItem> > > mColors;
CodeCompletionListItemDelegate* mDelegate;

View File

@ -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+1<currentCol) {
computeScroll(isDragging);
return;
}
}
// int currentCol=displayXY().Column;
// for (int i=startLine;i<=endLine;i++) {
// QString s = mDocument->getString(i-1);
// int cols = stringColumns(s,0);
// if (cols+1<currentCol) {
// computeScroll(isDragging);
// return;
// }
// }
}
// }
// changes to line / column in one go
incPaintLock();
auto action = finally([this]{

View File

@ -35,7 +35,11 @@ Document::Document(const QFont& font, const QFont& nonAsciiFont, QObject *parent
mFontMetrics(font),
mNonAsciiFontMetrics(nonAsciiFont),
mTabWidth(4),
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
mMutex()
#else
mMutex(QMutex::Recursive)
#endif
{
mAppendNewLineAtEOF = true;

View File

@ -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);
};