From 15b037aef77c47a83952d80329972105435bb428 Mon Sep 17 00:00:00 2001 From: evgeny Date: Wed, 21 Oct 2026 13:31:50 +0200 Subject: [PATCH] Scroll to latest chat messages with End key --- tools/chatgui/src/chatview.cpp | 2 ++ tools/chatgui/src/chatview.h | 2 +- tools/chatgui/tests/test_file_drop.cpp | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/chatgui/src/chatview.cpp b/tools/chatgui/src/chatview.cpp index 9953db5a..4e58808f 100644 --- a/tools/chatgui/src/chatview.cpp +++ b/tools/chatgui/src/chatview.cpp @@ -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); diff --git a/tools/chatgui/src/chatview.h b/tools/chatgui/src/chatview.h index 12a36d1c..e2d1ebfe 100644 --- a/tools/chatgui/src/chatview.h +++ b/tools/chatgui/src/chatview.h @@ -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; diff --git a/tools/chatgui/tests/test_file_drop.cpp b/tools/chatgui/tests/test_file_drop.cpp index 2b4b70d2..c9857a95 100644 --- a/tools/chatgui/tests/test_file_drop.cpp +++ b/tools/chatgui/tests/test_file_drop.cpp @@ -56,7 +56,7 @@ private slots: void historyKeyboardNavigation_data() { QTest::addColumn("key"); QTest::addColumn("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(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(key));