From 0681f61f51e350b55ee219fdb5a76f021ff122e8 Mon Sep 17 00:00:00 2001 From: Mac Date: Wed, 11 Nov 2026 14:57:41 -0500 Subject: [PATCH 1/3] Fix keyboard scrolling in folder views - Keep the current item visible after keyboard navigation. - Cover grid, list, and columns with real-view input tests. --- src/Selecting.qml | 2 + tests/folio_tests.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) diff --git a/src/Selecting.qml b/src/Selecting.qml index aa06c9e4..87a82eac 100644 --- a/src/Selecting.qml +++ b/src/Selecting.qml @@ -24,6 +24,8 @@ QtObject { return backend.folder.selectOnly(view.currentIndex) anchor = view.currentIndex + if (view.currentIndex >= 0) + view.positionViewAtIndex(view.currentIndex, ListView.Contain) } function click(index, modifiers) { diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index e5278791..f70970e0 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -5677,6 +5677,104 @@ private slots: QVERIFY(!FolderModel::toMap(FolderModel::Entry()).contains("peek")); } + void folderKeyboardScrolls_data() + { + QTest::addColumn("viewType"); + QTest::newRow("grid") << QString("FolderGrid"); + QTest::newRow("list") << QString("FolderList"); + QTest::newRow("columns") << QString("FolderColumns"); + } + + void folderKeyboardScrolls() + { + QFETCH(QString, viewType); + QTemporaryDir home; + QVERIFY(QDir(home.path()).mkdir("files")); + for (int i = 0; i < 80; ++i) + write(home.filePath(QString("files/file-%1.txt").arg(i, 2, 10, QLatin1Char('0'))), "x"); + Backend backend(home.path()); + backend.navigate(home.filePath("files")); + QTRY_COMPARE(backend.folder()->rowCount(), 80); + Theme theme(home.filePath("theme")); + FileOps fileOps; + Translator translator(home.filePath("language"), home.path()); + Thumbnails thumbnails(home.filePath("cache"), {home.filePath("none")}); + qmlRegisterType("Folio", 1, 0, "FolderModel"); + QQmlEngine engine; + engine.rootContext()->setContextProperty("backend", &backend); + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("fileOps", &fileOps); + engine.rootContext()->setContextProperty("translator", &translator); + engine.rootContext()->setContextProperty("plugins", QVariantMap{{"views", QVariantMap{}}}); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + QQmlComponent component(&engine); + component.setData(QString(R"( + import QtQuick + Window { + width: 600; height: 480; visible: true + readonly property var cursorView: folderView.menuAnchor() ? folderView.menuAnchor().parent.parent : null + %1 { id: folderView; anchors.fill: parent } + function start() { folderView.select(0, false); folderView.focusView() } + } + )").arg(viewType).toUtf8(), QUrl::fromLocalFile(sourceFolder() + "/KeyboardScrollTest.qml")); + std::unique_ptr root(component.create()); + QVERIFY2(root, qPrintable(component.errorString())); + auto *window = qobject_cast(root.get()); + QVERIFY(QTest::qWaitForWindowExposed(window)); + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QMetaObject::invokeMethod(root.get(), "start")); + auto *view = qvariant_cast(root->property("cursorView")); + QVERIFY(view); + QTRY_COMPARE(view->property("count").toInt(), 80); + const int step = viewType == "FolderGrid" ? view->property("columns").toInt() : 1; + const auto currentItem = [&] { return qvariant_cast(view->property("currentItem")); }; + const auto visible = [&] { + auto *item = currentItem(); + if (!item) + return false; + const qreal y = item->mapToItem(view, QPointF()).y(); + return y >= -0.5 && y + item->height() <= view->height() + 0.5; + }; + const auto offset = [&] { return view->property("contentY").toReal(); }; + QTRY_VERIFY(visible()); + const qreal start = offset(); + for (int i = 1; i <= 20; ++i) { + QTest::keyClick(window, Qt::Key_Down); + QCOMPARE(view->property("currentIndex").toInt(), i * step); + QCOMPARE(backend.folder()->selectedCount(), 1); + QVERIFY(backend.folder()->isSelected(i * step)); + QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); + } + QVERIFY(offset() > start); + for (int i = 19; i >= 0; --i) { + QTest::keyClick(window, Qt::Key_Up); + QCOMPARE(view->property("currentIndex").toInt(), i * step); + QCOMPARE(backend.folder()->selectedCount(), 1); + QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); + } + QCOMPARE(offset(), start); + for (int i = 1; i <= 20; ++i) { + QTest::keyClick(window, Qt::Key_Down, Qt::ShiftModifier); + QCOMPARE(view->property("currentIndex").toInt(), i * step); + QCOMPARE(backend.folder()->selectedCount(), i * step + 1); + QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); + } + const qreal beforeClick = offset(); + const QPoint click = view->mapToScene(QPointF(view->width() / 2, 10)).toPoint(); + QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, click); + QCOMPARE(backend.folder()->selectedCount(), 1); + QCOMPARE(offset(), beforeClick); + const int selected = view->property("currentIndex").toInt(); + const QPointF wheelAt = view->mapToScene(QPointF(view->width() / 2, view->height() / 2)); + QWheelEvent wheel(wheelAt, window->mapToGlobal(wheelAt), {}, QPoint(0, -120), + Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); + QGuiApplication::sendEvent(window, &wheel); + QTRY_VERIFY(offset() > beforeClick); + QCOMPARE(view->property("currentIndex").toInt(), selected); + QCOMPARE(backend.folder()->selectedCount(), 1); + } + void gridBandHitsTheTilesBothWays() { // The rubber band's hit areas sit where the grid put the tiles, also From 2cbda710aceb870cde4c2c722ec73f453929c0cd Mon Sep 17 00:00:00 2001 From: Mac Date: Sat, 14 Nov 2026 11:54:04 -0500 Subject: [PATCH 2/3] Test cursor visibility after scrolling and restoration - Cover arrow navigation after wheel scrolling the cursor offscreen. - Cover Down after clearing a cursor in a scrolled view. - Verify cursor restoration reveals the item and preserves selection. --- tests/folio_tests.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index f70970e0..c22faada 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -5715,6 +5715,8 @@ private slots: readonly property var cursorView: folderView.menuAnchor() ? folderView.menuAnchor().parent.parent : null %1 { id: folderView; anchors.fill: parent } function start() { folderView.select(0, false); folderView.focusView() } + function restore(row) { folderView.select(row, true) } + function clearCursor() { backend.folder.clearSelection(); folderView.letGo() } } )").arg(viewType).toUtf8(), QUrl::fromLocalFile(sourceFolder() + "/KeyboardScrollTest.qml")); std::unique_ptr root(component.create()); @@ -5767,12 +5769,40 @@ private slots: QCOMPARE(offset(), beforeClick); const int selected = view->property("currentIndex").toInt(); const QPointF wheelAt = view->mapToScene(QPointF(view->width() / 2, view->height() / 2)); - QWheelEvent wheel(wheelAt, window->mapToGlobal(wheelAt), {}, QPoint(0, -120), + QWheelEvent wheel(wheelAt, window->mapToGlobal(wheelAt), {}, QPoint(0, -720), Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); QGuiApplication::sendEvent(window, &wheel); QTRY_VERIFY(offset() > beforeClick); QCOMPARE(view->property("currentIndex").toInt(), selected); QCOMPARE(backend.folder()->selectedCount(), 1); + QTRY_VERIFY(currentItem()->mapToItem(view, QPointF()).y() + currentItem()->height() <= 0); + QTest::keyClick(window, Qt::Key_Down); + QCOMPARE(view->property("currentIndex").toInt(), selected + step); + QCOMPARE(backend.folder()->selectedCount(), 1); + QVERIFY(backend.folder()->isSelected(selected + step)); + QTRY_VERIFY(visible()); + + QVERIFY(QMetaObject::invokeMethod(view, "positionViewAtEnd")); + QTRY_VERIFY(offset() > start); + const qreal beforeClear = offset(); + QVERIFY(QMetaObject::invokeMethod(root.get(), "clearCursor")); + QCOMPARE(view->property("currentIndex").toInt(), -1); + QCOMPARE(backend.folder()->selectedCount(), 0); + QCOMPARE(offset(), beforeClear); + QTest::keyClick(window, Qt::Key_Down); + QCOMPARE(view->property("currentIndex").toInt(), 0); + QCOMPARE(backend.folder()->selectedCount(), 1); + QVERIFY(backend.folder()->isSelected(0)); + QTRY_VERIFY(visible()); + + backend.folder()->selectRange(5, 10, false); + QVERIFY(QMetaObject::invokeMethod(root.get(), "restore", Q_ARG(QVariant, 60))); + QCOMPARE(view->property("currentIndex").toInt(), 60); + QTRY_VERIFY(visible()); + QVERIFY(offset() > start); + QCOMPARE(backend.folder()->selectedCount(), 6); + for (int i = 5; i <= 10; ++i) + QVERIFY(backend.folder()->isSelected(i)); } void gridBandHitsTheTilesBothWays() From 4d0cd168d719fcac7e67d191488fd5a32588f811 Mon Sep 17 00:00:00 2001 From: Omarchybot <317366263+omarchybot@users.noreply.github.com> Date: Mon, 16 Nov 2026 09:18:42 +0100 Subject: [PATCH 3/3] Trim the keyboard scrolling test to the bug it covers The test now presses Down past the fold in each view and checks after every press that the cursor stays in sight, which is what fails without the fix, then that the cursor really went thirty items down, so arrows that stopped moving it can't pass for arrows that scroll. The Up, Shift, click, wheel, clear-cursor and restore steps exercised paths that already scrolled, or never scroll, on main, so they passed with or without it. Visibility is checked from the cursor's item in window coordinates, so the columns view needs no reach into its inner list. The guard before positionViewAtIndex goes too: the view already ignores an index of -1. Co-Authored-By: Claude Opus 5.5 Co-Authored-By: Codex Medium --- src/Selecting.qml | 3 +- tests/folio_tests.cpp | 96 +++++++------------------------------------ 2 files changed, 16 insertions(+), 83 deletions(-) diff --git a/src/Selecting.qml b/src/Selecting.qml index 87a82eac..ccb0e86f 100644 --- a/src/Selecting.qml +++ b/src/Selecting.qml @@ -24,8 +24,7 @@ QtObject { return backend.folder.selectOnly(view.currentIndex) anchor = view.currentIndex - if (view.currentIndex >= 0) - view.positionViewAtIndex(view.currentIndex, ListView.Contain) + view.positionViewAtIndex(view.currentIndex, ListView.Contain) } function click(index, modifiers) { diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 3f0da399..b3df244e 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -5822,97 +5822,31 @@ private slots: import QtQuick Window { width: 600; height: 480; visible: true - readonly property var cursorView: folderView.menuAnchor() ? folderView.menuAnchor().parent.parent : null - %1 { id: folderView; anchors.fill: parent } - function start() { folderView.select(0, false); folderView.focusView() } - function restore(row) { folderView.select(row, true) } - function clearCursor() { backend.folder.clearSelection(); folderView.letGo() } + property alias cursor: folderView.currentIndex + %1 { id: folderView; anchors.fill: parent; Component.onCompleted: focusView() } + function cursorInView() { + const item = folderView.menuAnchor() + const y = item ? item.mapToItem(null, 0, 0).y : -1 + return y >= 0 && y + item.height <= height + } } )").arg(viewType).toUtf8(), QUrl::fromLocalFile(sourceFolder() + "/KeyboardScrollTest.qml")); std::unique_ptr root(component.create()); QVERIFY2(root, qPrintable(component.errorString())); auto *window = qobject_cast(root.get()); - QVERIFY(QTest::qWaitForWindowExposed(window)); window->requestActivate(); QVERIFY(QTest::qWaitForWindowActive(window)); - QVERIFY(QMetaObject::invokeMethod(root.get(), "start")); - auto *view = qvariant_cast(root->property("cursorView")); - QVERIFY(view); - QTRY_COMPARE(view->property("count").toInt(), 80); - const int step = viewType == "FolderGrid" ? view->property("columns").toInt() : 1; - const auto currentItem = [&] { return qvariant_cast(view->property("currentItem")); }; - const auto visible = [&] { - auto *item = currentItem(); - if (!item) - return false; - const qreal y = item->mapToItem(view, QPointF()).y(); - return y >= -0.5 && y + item->height() <= view->height() + 0.5; + const auto cursorInView = [&] { + QVariant inView; + QMetaObject::invokeMethod(root.get(), "cursorInView", Q_RETURN_ARG(QVariant, inView)); + return inView.toBool(); }; - const auto offset = [&] { return view->property("contentY").toReal(); }; - QTRY_VERIFY(visible()); - const qreal start = offset(); - for (int i = 1; i <= 20; ++i) { + // Thirty presses take the cursor well past the fold in every view. + for (int i = 0; i < 30; ++i) { QTest::keyClick(window, Qt::Key_Down); - QCOMPARE(view->property("currentIndex").toInt(), i * step); - QCOMPARE(backend.folder()->selectedCount(), 1); - QVERIFY(backend.folder()->isSelected(i * step)); - QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); - } - QVERIFY(offset() > start); - for (int i = 19; i >= 0; --i) { - QTest::keyClick(window, Qt::Key_Up); - QCOMPARE(view->property("currentIndex").toInt(), i * step); - QCOMPARE(backend.folder()->selectedCount(), 1); - QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); + QTRY_VERIFY(cursorInView()); } - QCOMPARE(offset(), start); - for (int i = 1; i <= 20; ++i) { - QTest::keyClick(window, Qt::Key_Down, Qt::ShiftModifier); - QCOMPARE(view->property("currentIndex").toInt(), i * step); - QCOMPARE(backend.folder()->selectedCount(), i * step + 1); - QTRY_VERIFY_WITH_TIMEOUT(visible(), 1000); - } - const qreal beforeClick = offset(); - const QPoint click = view->mapToScene(QPointF(view->width() / 2, 10)).toPoint(); - QTest::mouseClick(window, Qt::LeftButton, Qt::NoModifier, click); - QCOMPARE(backend.folder()->selectedCount(), 1); - QCOMPARE(offset(), beforeClick); - const int selected = view->property("currentIndex").toInt(); - const QPointF wheelAt = view->mapToScene(QPointF(view->width() / 2, view->height() / 2)); - QWheelEvent wheel(wheelAt, window->mapToGlobal(wheelAt), {}, QPoint(0, -720), - Qt::NoButton, Qt::NoModifier, Qt::NoScrollPhase, false); - QGuiApplication::sendEvent(window, &wheel); - QTRY_VERIFY(offset() > beforeClick); - QCOMPARE(view->property("currentIndex").toInt(), selected); - QCOMPARE(backend.folder()->selectedCount(), 1); - QTRY_VERIFY(currentItem()->mapToItem(view, QPointF()).y() + currentItem()->height() <= 0); - QTest::keyClick(window, Qt::Key_Down); - QCOMPARE(view->property("currentIndex").toInt(), selected + step); - QCOMPARE(backend.folder()->selectedCount(), 1); - QVERIFY(backend.folder()->isSelected(selected + step)); - QTRY_VERIFY(visible()); - - QVERIFY(QMetaObject::invokeMethod(view, "positionViewAtEnd")); - QTRY_VERIFY(offset() > start); - const qreal beforeClear = offset(); - QVERIFY(QMetaObject::invokeMethod(root.get(), "clearCursor")); - QCOMPARE(view->property("currentIndex").toInt(), -1); - QCOMPARE(backend.folder()->selectedCount(), 0); - QCOMPARE(offset(), beforeClear); - QTest::keyClick(window, Qt::Key_Down); - QCOMPARE(view->property("currentIndex").toInt(), 0); - QCOMPARE(backend.folder()->selectedCount(), 1); - QVERIFY(backend.folder()->isSelected(0)); - QTRY_VERIFY(visible()); - - backend.folder()->selectRange(5, 10, false); - QVERIFY(QMetaObject::invokeMethod(root.get(), "restore", Q_ARG(QVariant, 60))); - QCOMPARE(view->property("currentIndex").toInt(), 60); - QTRY_VERIFY(visible()); - QVERIFY(offset() > start); - QCOMPARE(backend.folder()->selectedCount(), 6); - for (int i = 5; i <= 10; ++i) - QVERIFY(backend.folder()->isSelected(i)); + QVERIFY(root->property("cursor").toInt() >= 29); } void gridBandHitsTheTilesBothWays()