Scroll to latest chat messages with End key

This commit is contained in:
evgeny committed 2026-10-21 13:31:50 +02:00
1 parent 69e534304b
commit 15b037aef7
3 files changed
+7 -3

No files matched your search

+2
View File
@@ -237,8 +237,10 @@ bool ChatView::scrollWithKey(QKeyEvent *event) {
case Qt::Key_Down: action = QAbstractSlider::SliderSingleStepAdd; break;
case Qt::Key_PageUp: action = QAbstractSlider::SliderPageStepSub; break;
case Qt::Key_PageDown: action = QAbstractSlider::SliderPageStepAdd; break;
case Qt::Key_End: action = QAbstractSlider::SliderToMaximum; break;
default: return false;
}
if (event->key() == Qt::Key_End) emit latestRequested();
auto* bar = verticalScrollBar();
const int before = bar->value();
bar->triggerAction(action);
+1 -1
View File
@@ -42,7 +42,7 @@ signals:
void latestRequested();
protected:
/* Up/Down/PgUp/PgDown от поля ввода и окна, установивших этот вид как eventFilter. */
/* Up/Down/PgUp/PgDown/End от поля ввода и окна, установивших этот вид как eventFilter. */
bool eventFilter(QObject *object, QEvent *event) override;
bool viewportEvent(QEvent *event) override;
void paintEvent(QPaintEvent *event) override;
+4 -2
View File
@@ -56,7 +56,7 @@ private slots:
void historyKeyboardNavigation_data() {
QTest::addColumn<int>("key");
QTest::addColumn<int>("focus");
for (int key : {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageUp, Qt::Key_PageDown})
for (int key : {Qt::Key_Up, Qt::Key_Down, Qt::Key_PageUp, Qt::Key_PageDown, Qt::Key_End})
for (int focus = 0; focus < 3; focus++)
QTest::newRow(qPrintable(QStringLiteral("key-%1-focus-%2").arg(key).arg(focus))) << key << focus;
}
@@ -82,8 +82,10 @@ private slots:
const int before = bar->value();
const bool up = key == Qt::Key_Up || key == Qt::Key_PageUp;
const int step = key == Qt::Key_Up || key == Qt::Key_Down ? bar->singleStep() : bar->pageStep();
QSignalSpy latest(view, &ChatView::latestRequested);
QTest::keyClick(target, static_cast<Qt::Key>(key));
QCOMPARE(bar->value(), before + (up ? -step : step));
QCOMPARE(bar->value(), key == Qt::Key_End ? bar->maximum() : before + (up ? -step : step));
QCOMPARE(latest.count(), key == Qt::Key_End ? 1 : 0);
QCOMPARE(QApplication::focusWidget(), target); QCOMPARE(editor->textCursor().position(), 5); QCOMPARE(editor->toPlainText(), draft);
bar->setValue(up ? bar->minimum() : bar->maximum());
const int boundary = bar->value(); QTest::keyClick(target, static_cast<Qt::Key>(key));