- fix: Crash when drag the selection beyond the end of the document.

This commit is contained in:
Roy Qu 2023-03-23 15:56:07 +08:00
parent cdcf525157
commit 6eded18fd6
3 changed files with 19 additions and 10 deletions

View File

@ -3,6 +3,8 @@ Red Panda C++ Version 2.19
- fix: Crash when directive line ends with '\' and at the last line.
- fix: The option "Minimal indent for a continuous conditional beloning to a conditional header:" for formatter is not correct.
- fix: Crash when a project is removed from the disk while it is openned in RedPanda-C++.
- fix: The option "Open CPU info dialog when signal received" can't be correctly set in the options dialog's debugger page.
- fix: Crash when drag the selection beyond the end of the document.
Red Panda C++ Version 2.18

View File

@ -48,7 +48,7 @@ Document::Document(const QFont& font, const QFont& nonAsciiFont, QObject *parent
mCharWidth = mFontMetrics.horizontalAdvance("M");
}
static void ListIndexOutOfBounds(int index) {
static void listIndexOutOfBounds(int index) {
throw IndexOutOfRange(index);
}
@ -163,7 +163,7 @@ SyntaxState Document::getSyntaxState(int index)
if (index>=0 && index < mLines.size()) {
return mLines[index]->syntaxState;
} else {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
return SyntaxState();
}
@ -204,7 +204,7 @@ void Document::setSyntaxState(int Index, const SyntaxState& range)
{
QMutexLocker locker(&mMutex);
if (Index<0 || Index>=mLines.count()) {
ListIndexOutOfBounds(Index);
listIndexOutOfBounds(Index);
}
//beginUpdate();
mLines[Index]->syntaxState = range;
@ -341,7 +341,7 @@ void Document::deleteLines(int index, int numLines)
if (numLines<=0)
return;
if ((index < 0) || (index >= mLines.count())) {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
beginUpdate();
auto action = finally([this]{
@ -366,10 +366,10 @@ void Document::exchange(int index1, int index2)
{
QMutexLocker locker(&mMutex);
if ((index1 < 0) || (index1 >= mLines.count())) {
ListIndexOutOfBounds(index1);
listIndexOutOfBounds(index1);
}
if ((index2 < 0) || (index2 >= mLines.count())) {
ListIndexOutOfBounds(index2);
listIndexOutOfBounds(index2);
}
beginUpdate();
PDocumentLine temp = mLines[index1];
@ -388,7 +388,7 @@ void Document::insertLine(int index, const QString &s)
{
QMutexLocker locker(&mMutex);
if ((index < 0) || (index > mLines.count())) {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
beginUpdate();
insertItem(index, s);
@ -400,7 +400,7 @@ void Document::deleteAt(int index)
{
QMutexLocker locker(&mMutex);
if ((index < 0) || (index >= mLines.count())) {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
beginUpdate();
if (mIndexOfLongestLine == index)
@ -432,7 +432,7 @@ void Document::putLine(int index, const QString &s, bool notify) {
addLine(s);
} else {
if (index<0 || index>=mLines.count()) {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
beginUpdate();
int oldColumns = mLines[index]->columns;
@ -470,7 +470,7 @@ void Document::insertLines(int index, int numLines)
{
QMutexLocker locker(&mMutex);
if (index<0 || index>mLines.count()) {
ListIndexOutOfBounds(index);
listIndexOutOfBounds(index);
}
if (numLines<=0)
return;

View File

@ -6352,6 +6352,13 @@ void QSynEdit::dropEvent(QDropEvent *event)
mDropped = true;
return;
}
if (coord.line<=0 || coord.line>=mDocument->lengthOfLongestLine()) {
//do nothing if drag out of range
event->acceptProposedAction();
mDropped = true;
return;
}
int topLine = mTopLine;
int leftChar = mLeftChar;
QStringList text=splitStrings(event->mimeData()->text());