Fix reordering of various-height pinned chats.

Fixes #28948.
This commit is contained in:
John Preston 2025-02-10 16:54:28 +04:00
parent f3ed7c5e19
commit 443981ba31

View file

@ -2079,6 +2079,7 @@ bool InnerWidget::updateReorderPinned(QPoint localPosition) {
const auto draggingHeight = _dragging->height();
auto yaddWas = _pinnedRows[_draggingIndex].yadd.current();
auto shift = 0;
auto shiftHeight = 0;
auto now = crl::now();
if (_dragStart.y() > localPosition.y() && _draggingIndex > 0) {
shift = -floorclamp(_dragStart.y() - localPosition.y() + (draggingHeight / 2), draggingHeight, 0, _draggingIndex);
@ -2088,6 +2089,7 @@ bool InnerWidget::updateReorderPinned(QPoint localPosition) {
std::swap(_pinnedRows[from], _pinnedRows[from - 1]);
_pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() - draggingHeight, 0);
_pinnedRows[from].animStartTime = now;
shiftHeight -= (*(_shownList->cbegin() + from))->height();
}
} else if (_dragStart.y() < localPosition.y() && _draggingIndex + 1 < pinnedCount) {
shift = floorclamp(localPosition.y() - _dragStart.y() + (draggingHeight / 2), draggingHeight, 0, pinnedCount - _draggingIndex - 1);
@ -2097,18 +2099,21 @@ bool InnerWidget::updateReorderPinned(QPoint localPosition) {
std::swap(_pinnedRows[from], _pinnedRows[from + 1]);
_pinnedRows[from].yadd = anim::value(_pinnedRows[from].yadd.current() + draggingHeight, 0);
_pinnedRows[from].animStartTime = now;
shiftHeight += (*(_shownList->cbegin() + from))->height();
}
}
if (shift) {
_draggingIndex += shift;
_aboveIndex = _draggingIndex;
_dragStart.setY(_dragStart.y() + shift * _st->height);
_dragStart.setY(_dragStart.y() + shiftHeight);
if (!_pinnedShiftAnimation.animating()) {
_pinnedShiftAnimation.start();
}
}
_aboveTopShift = qCeil(_pinnedRows[_aboveIndex].yadd.current());
_pinnedRows[_draggingIndex].yadd = anim::value(yaddWas - shift * _st->height, localPosition.y() - _dragStart.y());
_pinnedRows[_draggingIndex].yadd = anim::value(
yaddWas - shiftHeight,
localPosition.y() - _dragStart.y());
if (!_pinnedRows[_draggingIndex].animStartTime) {
_pinnedRows[_draggingIndex].yadd.finish();
}
@ -2159,7 +2164,7 @@ bool InnerWidget::pinnedShiftAnimationCallback(crl::time now) {
}
if (updateMin >= 0) {
const auto minHeight = _st->height;
const auto maxHeight = st::forumDialogRow.height;
const auto maxHeight = st::taggedForumDialogRow.height;
auto top = pinnedOffset();
auto updateFrom = top + minHeight * (updateMin - 1);
auto updateHeight = maxHeight * (updateMax - updateMin + 3);