mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
fix(chatlog): update multi line selection on chatlog change
Fixes crash due to out of bound access. Fixes selection box jumping on history load. Fix #5769
This commit is contained in:
parent
badef48c3a
commit
2bba12175e
|
@ -34,6 +34,9 @@
|
|||
#include <QShortcut>
|
||||
#include <QTimer>
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
|
||||
/**
|
||||
* @var ChatLog::repNameAfter
|
||||
* @brief repetition interval sender name (sec)
|
||||
|
@ -454,6 +457,8 @@ void ChatLog::insertChatlinesOnTop(const QList<ChatLine::Ptr>& newLines)
|
|||
|
||||
lines = combLines;
|
||||
|
||||
moveSelectionRectDownIfMulti(newLines.size());
|
||||
|
||||
scene->setItemIndexMethod(oldIndexMeth);
|
||||
|
||||
// redo layout
|
||||
|
@ -722,6 +727,51 @@ void ChatLog::reloadTheme()
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adjusts the multi line selection rectangle based on chatlog changing lines
|
||||
* @param offset Amount to shift selection rect up by. Must be non-negative.
|
||||
*/
|
||||
void ChatLog::moveSelectionRectUpIfMulti(int offset)
|
||||
{
|
||||
assert(offset >= 0);
|
||||
if (selectionMode != Multi) {
|
||||
return;
|
||||
}
|
||||
if (selLastRow < offset) { // entire selection now out of bounds
|
||||
clearSelection();
|
||||
return;
|
||||
} else {
|
||||
selLastRow -= offset;
|
||||
}
|
||||
selClickedRow = std::max(0, selClickedRow - offset);
|
||||
selFirstRow = std::max(0, selFirstRow - offset);
|
||||
updateMultiSelectionRect();
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Adjusts the multi line selection rectangle based on chatlog changing lines
|
||||
* @param offset Amount to shift selection rect down by. Must be non-negative.
|
||||
*/
|
||||
void ChatLog::moveSelectionRectDownIfMulti(int offset)
|
||||
{
|
||||
assert(offset >= 0);
|
||||
if (selectionMode != Multi) {
|
||||
return;
|
||||
}
|
||||
const int lastLine = lines.size() - 1;
|
||||
if (selFirstRow + offset > lastLine) { // entire selection now out of bounds
|
||||
clearSelection();
|
||||
return;
|
||||
} else {
|
||||
selFirstRow += offset;
|
||||
}
|
||||
selClickedRow = std::min(lastLine, selClickedRow + offset);
|
||||
selLastRow = std::min(lastLine, selLastRow + offset);
|
||||
updateMultiSelectionRect();
|
||||
emit selectionChanged();
|
||||
}
|
||||
|
||||
void ChatLog::removeFirsts(const int num)
|
||||
{
|
||||
if (lines.size() > num) {
|
||||
|
@ -734,6 +784,8 @@ void ChatLog::removeFirsts(const int num)
|
|||
for (int i = 0; i < lines.size(); ++i) {
|
||||
lines[i]->setRow(i);
|
||||
}
|
||||
|
||||
moveSelectionRectUpIfMulti(num);
|
||||
}
|
||||
|
||||
void ChatLog::removeLasts(const int num)
|
||||
|
|
|
@ -58,6 +58,8 @@ public:
|
|||
void selectAll();
|
||||
void fontChanged(const QFont& font);
|
||||
void reloadTheme();
|
||||
void moveSelectionRectUpIfMulti(int offset);
|
||||
void moveSelectionRectDownIfMulti(int offset);
|
||||
void removeFirsts(const int num);
|
||||
void removeLasts(const int num);
|
||||
void setScroll(const bool scroll);
|
||||
|
|
Loading…
Reference in New Issue
Block a user