diff options
| author | Méven Car <[email protected]> | 2026-06-13 15:24:49 +0000 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2026-06-13 15:26:22 +0000 |
| commit | 5ccdce11680528d1e993bffe2cae8417b5aba8c8 (patch) | |
| tree | f8cb22d0ee7df3ec56af1cc265b74aa9f6e96582 /src/tests | |
| parent | d49b4aa1bc826bc2343f518af6712981228f1c8e (diff) | |
smoothscroller: always emit scrollingStopped from scrollTo
When scrollTo() is asked to move to the position the scrollbar already
holds (clamped, e.g. an item at the bottom, or a sub-pixel offset), no
animation runs and scrollingStopped() was never emitted. Callers waiting
for it stayed blocked: KItemListView::scrollToItem() delegates to scrollTo
for any non-zero offset, and DolphinView::renameSelectedItems() only opens
the inline rename editor once scrollingStopped() arrives. So inline rename
silently did nothing for the affected items.
Emit scrollingStopped() in the no-op case too, and add a regression test.
Diffstat (limited to 'src/tests')
| -rw-r--r-- | src/tests/CMakeLists.txt | 3 | ||||
| -rw-r--r-- | src/tests/kitemlistsmoothscrollertest.cpp | 68 |
2 files changed, 71 insertions, 0 deletions
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt index cac38deae..3ac657215 100644 --- a/src/tests/CMakeLists.txt +++ b/src/tests/CMakeLists.txt @@ -15,6 +15,9 @@ ecm_add_test(kitemsettest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test) # KItemRangeTest ecm_add_test(kitemrangetest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test) +# KItemListSmoothScrollerTest +ecm_add_test(kitemlistsmoothscrollertest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test) + # KItemListSelectionManagerTest ecm_add_test(kitemlistselectionmanagertest.cpp LINK_LIBRARIES dolphinprivate Qt6::Test) diff --git a/src/tests/kitemlistsmoothscrollertest.cpp b/src/tests/kitemlistsmoothscrollertest.cpp new file mode 100644 index 000000000..ac0a81d31 --- /dev/null +++ b/src/tests/kitemlistsmoothscrollertest.cpp @@ -0,0 +1,68 @@ +/* + * SPDX-FileCopyrightText: 2025 Méven Car <[email protected]> + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "kitemviews/private/kitemlistsmoothscroller.h" + +#include <QScrollBar> +#include <QSignalSpy> +#include <QStandardPaths> +#include <QTest> + +class KItemListSmoothScrollerTest : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void initTestCase(); + void testScrollToCurrentPositionEmitsScrollingStopped(); + void testScrollToClampedPositionEmitsScrollingStopped(); +}; + +void KItemListSmoothScrollerTest::initTestCase() +{ + QStandardPaths::setTestModeEnabled(true); +} + +void KItemListSmoothScrollerTest::testScrollToCurrentPositionEmitsScrollingStopped() +{ + // KItemListView::scrollToItem() delegates to KItemListSmoothScroller::scrollTo() + // for any non-zero offset and then relies on scrollingStopped() to know when the + // view settled. Callers such as DolphinView::renameSelectedItems() only open the + // inline rename editor once scrollingStopped() arrives. If scrollTo() is asked to + // move to the position the scrollbar is already at, no animation runs, so it must + // still emit scrollingStopped() or the editor never appears. + QScrollBar scrollBar(Qt::Vertical); + scrollBar.setRange(0, 100); + scrollBar.setValue(50); + + KItemListSmoothScroller scroller(&scrollBar); + QSignalSpy spy(&scroller, &KItemListSmoothScroller::scrollingStopped); + + scroller.scrollTo(scrollBar.value()); + + QCOMPARE(spy.count(), 1); +} + +void KItemListSmoothScrollerTest::testScrollToClampedPositionEmitsScrollingStopped() +{ + // Reproduces renaming an item at the very bottom: the scrollbar is already at its + // maximum, scrollToItem() still computes a non-zero offset and requests a further + // scroll, but the clamped target equals the current value, so nothing moves. + QScrollBar scrollBar(Qt::Vertical); + scrollBar.setRange(0, 100); + scrollBar.setValue(scrollBar.maximum()); + + KItemListSmoothScroller scroller(&scrollBar); + QSignalSpy spy(&scroller, &KItemListSmoothScroller::scrollingStopped); + + scroller.scrollTo(scrollBar.maximum() + 50); + + QCOMPARE(spy.count(), 1); +} + +QTEST_MAIN(KItemListSmoothScrollerTest) + +#include "kitemlistsmoothscrollertest.moc" |
