From e841157775a614e1498ba16504638938a7e276af Mon Sep 17 00:00:00 2001 From: kevinpardo Date: Wed, 11 Nov 2026 01:58:40 +0100 Subject: [PATCH 1/6] =?UTF-8?q?Move=20the=20preview=20to=20the=20item=20ab?= =?UTF-8?q?ove=20or=20below=20with=20=E2=86=91=20and=20=E2=86=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In the preview, ↑ and ↓ only scrolled, so on a picture, a video or a folder they did nothing, and in the list and column views, where files sit one above the other, there was no way to step to the next one with the keys that move through them in the folder. Now ↑ and ↓ still scroll what's taller than the window (a long text, a zoomed picture, a PDF), and anything that fits moves to the item above or below as the folder view lays them out: the row above or below in the list and columns, the tile above or below in the grid. The preview asks Folio with a "step -1" or "step 1" line, since only the window knows its layout; Folio moves its selection and sends the new item back as it already does. A preview running on its own falls back to the previous and next file. Co-Authored-By: Claude Opus 5.5 --- src/FolderColumns.qml | 2 ++ src/FolderGrid.qml | 2 ++ src/FolderList.qml | 2 ++ src/FolderPane.qml | 1 + src/PreviewWindow.qml | 18 +++++++++++++++--- src/backend.cpp | 4 ++++ src/backend.h | 3 +++ src/previewer.cpp | 9 +++++++++ src/previewer.h | 7 ++++++- tests/folio_tests.cpp | 22 ++++++++++++++++++++++ 10 files changed, 66 insertions(+), 4 deletions(-) diff --git a/src/FolderColumns.qml b/src/FolderColumns.qml index e8e26607..4542bd6b 100644 --- a/src/FolderColumns.qml +++ b/src/FolderColumns.qml @@ -21,6 +21,8 @@ Item { Selecting { id: selecting; view: here; pageStep: Math.max(1, Math.floor(here.height / 32) - 1) } function focusView() { here.forceActiveFocus() } + // The preview's ↑ and ↓: the row above or below in the current column. + function stepRow(direction) { direction < 0 ? here.decrementCurrentIndex() : here.incrementCurrentIndex() } function menuAnchor() { return here.currentItem } // Every column has a menu: on an item there, or on the column's folder. diff --git a/src/FolderGrid.qml b/src/FolderGrid.qml index e64bc139..27dbcaf1 100644 --- a/src/FolderGrid.qml +++ b/src/FolderGrid.qml @@ -11,6 +11,8 @@ GridView { signal cursorLetGo() function letGo() { selecting.letGo(); cursorLetGo() } function focusView() { forceActiveFocus() } + // The preview's ↑ and ↓: the tile above or below, as the arrow keys move here. + function stepRow(direction) { direction < 0 ? moveCurrentIndexUp() : moveCurrentIndexDown() } // Where the keyboard's menu (Alt+Return) opens: beside the cursor's item. function menuAnchor() { return currentItem } diff --git a/src/FolderList.qml b/src/FolderList.qml index 518cd483..2a79ebe9 100644 --- a/src/FolderList.qml +++ b/src/FolderList.qml @@ -14,6 +14,8 @@ FileListView { signal cursorLetGo() function letGo() { selecting.letGo(); cursorLetGo() } function focusView() { forceActiveFocus() } + // The preview's ↑ and ↓: the row above or below. + function stepRow(direction) { direction < 0 ? decrementCurrentIndex() : incrementCurrentIndex() } // Where the keyboard's menu (Alt+Return) opens: beside the cursor's item. function menuAnchor() { return currentItem } diff --git a/src/FolderPane.qml b/src/FolderPane.qml index aef2751c..43dc1fb9 100644 --- a/src/FolderPane.qml +++ b/src/FolderPane.qml @@ -233,6 +233,7 @@ FocusScope { Connections { target: backend function onSelectRequested(name) { if (view.item) view.item.select(backend.folder.indexOf(name), false) } + function onStepRequested(direction) { if (view.item) view.item.stepRow(direction) } function onActivateRequested() { if (pane.host) { pane.host.raise(); pane.host.requestActivate() } } } diff --git a/src/PreviewWindow.qml b/src/PreviewWindow.qml index 2b710086..3c3129ce 100644 --- a/src/PreviewWindow.qml +++ b/src/PreviewWindow.qml @@ -59,8 +59,20 @@ ApplicationWindow { Shortcut { sequence: "Left"; context: Qt.ApplicationShortcut; onActivated: win.rtl ? previewer.next() : previewer.previous() } Shortcut { sequence: "Right"; context: Qt.ApplicationShortcut; onActivated: win.rtl ? previewer.previous() : previewer.next() } Shortcut { sequences: ["Return", "Enter"]; context: Qt.ApplicationShortcut; onActivated: previewer.open() } - Shortcut { sequences: ["Up"]; context: Qt.ApplicationShortcut; onActivated: win.call("scroll", -1) } - Shortcut { sequences: ["Down"]; context: Qt.ApplicationShortcut; onActivated: win.call("scroll", 1) } + // ↑ and ↓ scroll what's taller than the window (a long text, a zoomed + // picture, a PDF); anything that fits moves to the item above or below, + // as the arrows do in the folder. + function upDown(direction) { + const v = win.view + const scrolls = v && typeof v.scroll === "function" + && (v.contentHeight === undefined || v.contentHeight > v.height + 1) + if (scrolls) + v.scroll(direction) + else + previewer.stepRow(direction) + } + Shortcut { sequences: ["Up"]; context: Qt.ApplicationShortcut; onActivated: win.upDown(-1) } + Shortcut { sequences: ["Down"]; context: Qt.ApplicationShortcut; onActivated: win.upDown(1) } Shortcut { sequences: [StandardKey.MoveToPreviousPage]; context: Qt.ApplicationShortcut; onActivated: win.call("page", -1) } Shortcut { sequences: [StandardKey.MoveToNextPage]; context: Qt.ApplicationShortcut; onActivated: win.call("page", 1) } Shortcut { sequences: [StandardKey.ZoomIn, "Ctrl+="]; context: Qt.ApplicationShortcut; onActivated: win.call("zoomBy", 1.25) } @@ -188,7 +200,7 @@ ApplicationWindow { visible: win.helpVisible onDismissed: win.helpVisible = false groups: [{ title: qsTr("Preview"), shortcuts: [ - [qsTr("Previous / next file"), win.rtl ? [["→"], ["←"]] : [["←"], ["→"]]], + [qsTr("Previous / next file"), (win.rtl ? [["→"], ["←"]] : [["←"], ["→"]]).concat([["↑"], ["↓"]])], [qsTr("Open in its app"), [["⏎"]]], [qsTr("Scroll"), [["↑", "↓"], ["Page Up"], ["Page Down"]]], [qsTr("Zoom in / out"), [["Ctrl", "="], ["Ctrl", "-"]]], diff --git a/src/backend.cpp b/src/backend.cpp index 878f98ba..c4710fad 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -43,6 +43,10 @@ Backend::Backend(const QString &home, QObject *parent) connect(&m_preview, &QProcess::readyReadStandardOutput, this, [this] { while (m_preview.canReadLine()) { const QString shown = QString::fromUtf8(m_preview.readLine()).trimmed(); + if (shown.startsWith("step ")) { + emit stepRequested(shown.mid(5).toInt() < 0 ? -1 : 1); + continue; + } m_previewed = shown; const QFileInfo info(shown); if (info.absolutePath() == path()) diff --git a/src/backend.h b/src/backend.h index 4e5ea958..26fb4e8f 100644 --- a/src/backend.h +++ b/src/backend.h @@ -150,6 +150,9 @@ class Backend : public QObject { void newWindowRequested(const QString &path); void chosen(const QString &path); void selectRequested(const QString &name); + // The preview's ↑ or ↓ on a file it can't scroll: move one row in the + // folder view, whose layout only this window knows. + void stepRequested(int direction); void activateRequested(); private: diff --git a/src/previewer.cpp b/src/previewer.cpp index 91735f27..025d37f4 100644 --- a/src/previewer.cpp +++ b/src/previewer.cpp @@ -201,6 +201,15 @@ void Previewer::previous() { setIndex(m_index - 1, true); } +void Previewer::stepRow(int direction) { + if (!m_reporting) { + direction < 0 ? previous() : next(); + return; + } + std::fprintf(stdout, "step %d\n", direction < 0 ? -1 : 1); + std::fflush(stdout); +} + void Previewer::open() { if (m_index >= 0) { // The same lookup as opening from the folder: the type's default diff --git a/src/previewer.h b/src/previewer.h index 0bd4d1c2..ab1b2ab1 100644 --- a/src/previewer.h +++ b/src/previewer.h @@ -16,7 +16,9 @@ // // Talks to the Folio window that started it over stdin and stdout, one path // per line: Folio writes the item selected in its grid, the preview writes -// the item it steps to, and each side follows the other. +// the item it steps to, and each side follows the other. ↑ and ↓ are written +// as "step -1" and "step 1": rows belong to the folder view, so Folio moves +// its selection and sends the new item back. class Previewer : public QObject { Q_OBJECT // Listing the folder only changes where the item sits among its @@ -57,6 +59,9 @@ class Previewer : public QObject { Q_INVOKABLE void next(); Q_INVOKABLE void previous(); + // ↑ or ↓: the item above or below in the Folio window's view, or the + // previous or next file when the preview runs on its own. + Q_INVOKABLE void stepRow(int direction); Q_INVOKABLE void open(); // Which view shows a type: image, animated, thumbnail, video, audio, diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 6a0aeeb4..3d0d1dbd 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7639,6 +7639,28 @@ private slots: QCOMPARE(buffers(), QVariantList(buffers().size(), 0)); } + void previewerStepsByRowOnItsOwn() + { + QTemporaryDir dir; + write(dir.filePath("a.png"), "a"); + write(dir.filePath("b.png"), "b"); + write(dir.filePath("c.png"), "c"); + + // Without a Folio window to ask for the row above or below, ↑ and ↓ + // fall back to the previous and next file. + Previewer previewer; + previewer.start(dir.filePath("b.png"), false, "name"); + QTRY_COMPARE(previewer.count(), 3); + QCOMPARE(previewer.index(), 1); + previewer.stepRow(1); + QCOMPARE(previewer.index(), 2); + previewer.stepRow(1); + QCOMPARE(previewer.index(), 2); + previewer.stepRow(-1); + previewer.stepRow(-1); + QCOMPARE(previewer.index(), 0); + } + void themeFallsBack() { QTemporaryDir dir; From 62298f34d87ccffb23a77c691abb1ea9145ab67c Mon Sep 17 00:00:00 2001 From: kevinpardo Date: Thu, 12 Nov 2026 01:40:53 +0100 Subject: [PATCH 2/6] Hold the preview's arrows until Folio has stepped a row, and while text loads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit After ↑ or ↓ the preview asked Folio for the row above or below, but an arrow pressed before the answer was taken from the old item: ↓ then → in a grid undid the ↓. Folio now sends the new item at once and then "stepped", and the preview keeps the arrows that came meanwhile until it does (a second at most, if no answer comes). A text still being read looked short, so ↑ and ↓ stepped past a long file on a slow mount. They do nothing until the text is in. Co-Authored-By: Claude Opus 5.5 --- src/FolderPane.qml | 4 +- src/PreviewWindow.qml | 4 ++ src/backend.cpp | 5 +++ src/previewer.cpp | 85 +++++++++++++++++++++++++++++++++---------- src/previewer.h | 28 ++++++++++++-- tests/folio_tests.cpp | 54 +++++++++++++++++++++++++++ 6 files changed, 156 insertions(+), 24 deletions(-) diff --git a/src/FolderPane.qml b/src/FolderPane.qml index 43dc1fb9..a679a939 100644 --- a/src/FolderPane.qml +++ b/src/FolderPane.qml @@ -233,7 +233,9 @@ FocusScope { Connections { target: backend function onSelectRequested(name) { if (view.item) view.item.select(backend.folder.indexOf(name), false) } - function onStepRequested(direction) { if (view.item) view.item.stepRow(direction) } + // Followed now, not later as a re-read is: the preview waits for the + // new item before its next arrow. + function onStepRequested(direction) { if (view.item) { view.item.stepRow(direction); pane.follow() } } function onActivateRequested() { if (pane.host) { pane.host.raise(); pane.host.requestActivate() } } } diff --git a/src/PreviewWindow.qml b/src/PreviewWindow.qml index 3c3129ce..d704b44b 100644 --- a/src/PreviewWindow.qml +++ b/src/PreviewWindow.qml @@ -63,6 +63,10 @@ ApplicationWindow { // picture, a PDF); anything that fits moves to the item above or below, // as the arrows do in the folder. function upDown(direction) { + // A text still being read looks short; stepping past it then would + // skip a long one. The next press, once it's in, knows which. + if (previewer.readingText) + return const v = win.view const scrolls = v && typeof v.scroll === "function" && (v.contentHeight === undefined || v.contentHeight > v.height + 1) diff --git a/src/backend.cpp b/src/backend.cpp index c4710fad..0b751237 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -44,7 +44,12 @@ Backend::Backend(const QString &home, QObject *parent) while (m_preview.canReadLine()) { const QString shown = QString::fromUtf8(m_preview.readLine()).trimmed(); if (shown.startsWith("step ")) { + // The view moves and sends its new item right away (or + // nothing, at the first or last row); "stepped" after it + // lets the preview take the arrows that came meanwhile. emit stepRequested(shown.mid(5).toInt() < 0 ? -1 : 1); + if (previewing()) + m_preview.write("stepped\n"); continue; } m_previewed = shown; diff --git a/src/previewer.cpp b/src/previewer.cpp index 025d37f4..1bc954be 100644 --- a/src/previewer.cpp +++ b/src/previewer.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -191,23 +192,64 @@ QString Previewer::type() const { return QMimeDatabase().mimeTypeForName(m_readType.isEmpty() ? m_entries.at(m_index).mime : m_readType).comment(); } -void Previewer::next() { - if (m_index + 1 < m_entries.size()) - setIndex(m_index + 1, true); +void Previewer::next() { move(Move::Next); } +void Previewer::previous() { move(Move::Previous); } +void Previewer::stepRow(int direction) { move(direction < 0 ? Move::Up : Move::Down); } + +void Previewer::move(Move move) { + if (m_awaitingStep) { + m_queued.append(move); + return; + } + // On its own, the preview has no rows: ↑ and ↓ go to the previous and + // next file. + if (!m_reporting && (move == Move::Up || move == Move::Down)) + move = move == Move::Up ? Move::Previous : Move::Next; + switch (move) { + case Move::Previous: + if (m_index > 0) + setIndex(m_index - 1, true); + break; + case Move::Next: + if (m_index + 1 < m_entries.size()) + setIndex(m_index + 1, true); + break; + case Move::Up: + case Move::Down: { + m_awaitingStep = true; + // A reply that never comes (a Folio too old to send it, or stuck) + // holds the arrows for a second, not for good. + const quint64 step = ++m_step; + QTimer::singleShot(1000, this, [this, step] { + if (step == m_step) + stepped(); + }); + report(move == Move::Up ? "step -1" : "step 1"); + break; + } + } } -void Previewer::previous() { - if (m_index > 0) - setIndex(m_index - 1, true); +void Previewer::stepped() { + m_awaitingStep = false; + ++m_step; + while (!m_awaitingStep && !m_queued.isEmpty()) + move(m_queued.takeFirst()); } -void Previewer::stepRow(int direction) { - if (!m_reporting) { - direction < 0 ? previous() : next(); - return; +void Previewer::receive(const QString &line) { + if (line == "stepped") + stepped(); + else if (!line.isEmpty()) + show(line); +} + +void Previewer::report(const QString &line) { + emit reported(line); + if (m_overStdio) { + std::fprintf(stdout, "%s\n", line.toUtf8().constData()); + std::fflush(stdout); } - std::fprintf(stdout, "step %d\n", direction < 0 ? -1 : 1); - std::fflush(stdout); } void Previewer::open() { @@ -227,6 +269,7 @@ void Previewer::setIndex(int index, bool report) { m_viewer = viewerFor(e.mime, e.isDir); m_text.clear(); m_readType.clear(); + m_readingText = false; // A folder's count and first pictures, and a text's opening part, are // read off the UI thread: a big folder, or any file on a slow mount, @@ -237,6 +280,7 @@ void Previewer::setIndex(int index, bool report) { // A file its extension could not name is named by what it holds, read with the rest and kept apart from the listing. const bool unnamed = e.mime == "application/octet-stream"; if (count || text || unnamed) { + m_readingText = text; auto *watcher = new QFutureWatcher>(this); connect(watcher, &QFutureWatcherBase::finished, this, [this, watcher, generation, unnamed] { watcher->deleteLater(); @@ -249,6 +293,7 @@ void Previewer::setIndex(int index, bool report) { m_entries[m_index] = entry; m_text = read; m_viewer = viewerFor(entry.mime, entry.isDir); + m_readingText = false; // A ".txt" that turns out to be binary is shown as a plain file. if ((m_viewer == "text" || m_viewer == "markdown") && m_text.isEmpty() && entry.size > 0) m_viewer = "other"; @@ -270,14 +315,15 @@ void Previewer::setIndex(int index, bool report) { emit changed(); emit listed(); - if (report && m_reporting) { - std::fprintf(stdout, "%s\n", e.path.toUtf8().constData()); - std::fflush(stdout); - } + if (report && m_reporting) + this->report(e.path); } -void Previewer::connectToFolio() { +void Previewer::connectToFolio(bool overStdio) { m_reporting = true; + m_overStdio = overStdio; + if (!overStdio) + return; m_stdin = new QSocketNotifier(STDIN_FILENO, QSocketNotifier::Read, this); connect(m_stdin, &QSocketNotifier::activated, this, [this] { char buffer[4096]; @@ -290,10 +336,9 @@ void Previewer::connectToFolio() { m_pending.append(buffer, n); int newline; while ((newline = m_pending.indexOf('\n')) >= 0) { - const QString path = QString::fromUtf8(m_pending.left(newline)); + const QString line = QString::fromUtf8(m_pending.left(newline)); m_pending.remove(0, newline + 1); - if (!path.isEmpty()) - show(path); + receive(line); } }); } diff --git a/src/previewer.h b/src/previewer.h index ab1b2ab1..5be66781 100644 --- a/src/previewer.h +++ b/src/previewer.h @@ -18,7 +18,8 @@ // per line: Folio writes the item selected in its grid, the preview writes // the item it steps to, and each side follows the other. ↑ and ↓ are written // as "step -1" and "step 1": rows belong to the folder view, so Folio moves -// its selection and sends the new item back. +// its selection, sends the new item back, then "stepped". Arrows pressed +// before that wait for it: taken from the old item, they'd undo the move. class Previewer : public QObject { Q_OBJECT // Listing the folder only changes where the item sits among its @@ -30,6 +31,9 @@ class Previewer : public QObject { Q_PROPERTY(QString viewer READ viewer NOTIFY changed) Q_PROPERTY(QString url READ url NOTIFY changed) Q_PROPERTY(QString text READ text NOTIFY changed) + // A text's opening part is still being read: until it's in, its length + // (whether ↑ and ↓ scroll it or step past it) isn't known. + Q_PROPERTY(bool readingText READ readingText NOTIFY changed) Q_PROPERTY(QString type READ type NOTIFY changed) public: @@ -41,8 +45,12 @@ class Previewer : public QObject { // Shows the file right away, then lists its folder in the background so // the arrow keys can step to its neighbours. void start(const QString &path, bool showHidden, const QString &sort); - // Reads paths from stdin and reports steps on stdout. - void connectToFolio(); + // Reads paths from stdin and reports steps on stdout; the tests leave + // stdin and stdout alone and talk through receive() and reported(). + void connectToFolio(bool overStdio = true); + // One line from Folio: a path to show, or "stepped" once it has moved a + // row for ↑ or ↓. + void receive(const QString &line); // Shows another file; one in the same folder keeps the list. void show(const QString &path); // Lists the folder again, keeping the file shown: after a language @@ -55,6 +63,7 @@ class Previewer : public QObject { QString viewer() const { return m_viewer; } QString url() const; QString text() const { return m_text; } + bool readingText() const { return m_readingText; } QString type() const; Q_INVOKABLE void next(); @@ -81,9 +90,15 @@ class Previewer : public QObject { void listed(); // The item was handed to its app, and the preview has done its part. void opened(); + // A line for Folio: the path stepped to, or "step -1" / "step 1". + void reported(const QString &line); private: + enum class Move { Previous, Next, Up, Down }; + void move(Move move); + void stepped(); void setIndex(int index, bool report); + void report(const QString &line); Opener m_opener; QVector m_entries; @@ -92,6 +107,7 @@ class Previewer : public QObject { QString m_text; // The type read from what the shown file holds when its name gave none, for this showing only: a file written since is read again. QString m_readType; + bool m_readingText = false; bool m_showHidden = false; QString m_sort = "name"; quint64 m_generation = 0; @@ -99,6 +115,12 @@ class Previewer : public QObject { // or skipped when they haven't started. std::shared_ptr> m_reading = std::make_shared>(0); bool m_reporting = false; + bool m_overStdio = false; + // Set from a "step" until Folio's "stepped"; the arrows pressed meanwhile + // wait in m_queued, in order. + bool m_awaitingStep = false; + quint64 m_step = 0; + QVector m_queued; QSocketNotifier *m_stdin = nullptr; QByteArray m_pending; }; diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 3d0d1dbd..6cc2cc99 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7661,6 +7661,60 @@ private slots: QCOMPARE(previewer.index(), 0); } + void previewerHoldsArrowsUntilFolioHasStepped() + { + QTemporaryDir dir; + for (const char *name : {"a.png", "b.png", "c.png", "d.png"}) + write(dir.filePath(name), "x"); + + Previewer previewer; + previewer.connectToFolio(false); + QSignalSpy reported(&previewer, &Previewer::reported); + previewer.start(dir.filePath("a.png"), false, "name"); + QTRY_COMPARE(previewer.count(), 4); + + // ↓ then → before Folio answers: → waits, and is taken from the item + // Folio moved to, not from a.png. + previewer.stepRow(1); + previewer.next(); + QCOMPARE(reported.count(), 1); + QCOMPARE(reported.at(0).at(0).toString(), QString("step 1")); + previewer.receive(dir.filePath("c.png")); + QCOMPARE(previewer.index(), 2); + QCOMPARE(reported.count(), 1); + previewer.receive("stepped"); + QCOMPARE(previewer.index(), 3); + QCOMPARE(reported.count(), 2); + QCOMPARE(reported.at(1).at(0).toString(), QFileInfo(dir.filePath("d.png")).absoluteFilePath()); + + // At the last row Folio doesn't move, and only says it has stepped. + previewer.stepRow(1); + previewer.previous(); + previewer.receive("stepped"); + QCOMPARE(previewer.index(), 2); + + // A reply that never comes holds the arrows for a moment only. + previewer.stepRow(-1); + previewer.previous(); + QCOMPARE(previewer.index(), 2); + QTRY_COMPARE(previewer.index(), 1); + } + + void previewerSaysWhileItReadsText() + { + QTemporaryDir dir; + write(dir.filePath("long.txt"), QByteArray(4096, 'x')); + write(dir.filePath("b.png"), "b"); + + Previewer previewer; + previewer.start(dir.filePath("long.txt"), false, "name"); + QVERIFY(previewer.readingText()); + QTRY_VERIFY(!previewer.readingText()); + QCOMPARE(previewer.text().size(), 4096); + previewer.show(dir.filePath("b.png")); + QVERIFY(!previewer.readingText()); + } + void themeFallsBack() { QTemporaryDir dir; From 5417643580081b5c1799f71b19c786c1eab2cb89 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 15:44:54 +0100 Subject: [PATCH 3/6] Let arrows go while Folio steps a row, rather than replay them MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Arrows pressed while the preview waited for Folio to step a row were queued and replayed once it had. Replayed, they were taken from a file nobody had looked at yet: a second ↓ queued on a picture stepped past the long text or PDF the first ↓ reached instead of scrolling it, or before its text was read; and a → queued behind a ↓ onto an opened folder's first child was played against a list of one, and lost. Folio answers a step within milliseconds, sooner than a held key repeats, so the arrows pressed in between are now simply let go, and the next one is judged from the file the step reached. Co-Authored-By: Claude Opus 5.5 --- src/previewer.cpp | 9 +++------ src/previewer.h | 6 +++--- tests/folio_tests.cpp | 21 ++++++++++++++------- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/previewer.cpp b/src/previewer.cpp index 1bc954be..b2332ec2 100644 --- a/src/previewer.cpp +++ b/src/previewer.cpp @@ -197,10 +197,9 @@ void Previewer::previous() { move(Move::Previous); } void Previewer::stepRow(int direction) { move(direction < 0 ? Move::Up : Move::Down); } void Previewer::move(Move move) { - if (m_awaitingStep) { - m_queued.append(move); + // Folio answers within milliseconds, sooner than a key repeats. + if (m_awaitingStep) return; - } // On its own, the preview has no rows: ↑ and ↓ go to the previous and // next file. if (!m_reporting && (move == Move::Up || move == Move::Down)) @@ -218,7 +217,7 @@ void Previewer::move(Move move) { case Move::Down: { m_awaitingStep = true; // A reply that never comes (a Folio too old to send it, or stuck) - // holds the arrows for a second, not for good. + // stills the arrows for a second, not for good. const quint64 step = ++m_step; QTimer::singleShot(1000, this, [this, step] { if (step == m_step) @@ -233,8 +232,6 @@ void Previewer::move(Move move) { void Previewer::stepped() { m_awaitingStep = false; ++m_step; - while (!m_awaitingStep && !m_queued.isEmpty()) - move(m_queued.takeFirst()); } void Previewer::receive(const QString &line) { diff --git a/src/previewer.h b/src/previewer.h index 5be66781..5d7cb44f 100644 --- a/src/previewer.h +++ b/src/previewer.h @@ -19,7 +19,8 @@ // the item it steps to, and each side follows the other. ↑ and ↓ are written // as "step -1" and "step 1": rows belong to the folder view, so Folio moves // its selection, sends the new item back, then "stepped". Arrows pressed -// before that wait for it: taken from the old item, they'd undo the move. +// before that are let go: taken from the old item, they'd undo the move, +// and replayed later, from a file not yet looked at, they'd skip it. class Previewer : public QObject { Q_OBJECT // Listing the folder only changes where the item sits among its @@ -117,10 +118,9 @@ class Previewer : public QObject { bool m_reporting = false; bool m_overStdio = false; // Set from a "step" until Folio's "stepped"; the arrows pressed meanwhile - // wait in m_queued, in order. + // are let go. bool m_awaitingStep = false; quint64 m_step = 0; - QVector m_queued; QSocketNotifier *m_stdin = nullptr; QByteArray m_pending; }; diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 6cc2cc99..e726765b 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7661,7 +7661,7 @@ private slots: QCOMPARE(previewer.index(), 0); } - void previewerHoldsArrowsUntilFolioHasStepped() + void previewerLetsArrowsGoUntilFolioHasStepped() { QTemporaryDir dir; for (const char *name : {"a.png", "b.png", "c.png", "d.png"}) @@ -7673,31 +7673,38 @@ private slots: previewer.start(dir.filePath("a.png"), false, "name"); QTRY_COMPARE(previewer.count(), 4); - // ↓ then → before Folio answers: → waits, and is taken from the item - // Folio moved to, not from a.png. + // ↓ then → and ↓ before Folio answers: they're let go, rather than + // taken from a.png (undoing the move) or replayed past c.png before + // it's been looked at. previewer.stepRow(1); previewer.next(); + previewer.stepRow(1); QCOMPARE(reported.count(), 1); QCOMPARE(reported.at(0).at(0).toString(), QString("step 1")); previewer.receive(dir.filePath("c.png")); + previewer.receive("stepped"); QCOMPARE(previewer.index(), 2); QCOMPARE(reported.count(), 1); - previewer.receive("stepped"); + // Once it has, the arrows are taken from where Folio moved to. + previewer.next(); QCOMPARE(previewer.index(), 3); QCOMPARE(reported.count(), 2); QCOMPARE(reported.at(1).at(0).toString(), QFileInfo(dir.filePath("d.png")).absoluteFilePath()); // At the last row Folio doesn't move, and only says it has stepped. previewer.stepRow(1); - previewer.previous(); previewer.receive("stepped"); + QCOMPARE(previewer.index(), 3); + previewer.previous(); QCOMPARE(previewer.index(), 2); - // A reply that never comes holds the arrows for a moment only. + // A reply that never comes stills the arrows for a moment only. previewer.stepRow(-1); previewer.previous(); QCOMPARE(previewer.index(), 2); - QTRY_COMPARE(previewer.index(), 1); + QTest::qWait(1100); + previewer.previous(); + QCOMPARE(previewer.index(), 1); } void previewerSaysWhileItReadsText() From 86c66c82ccf7db4df51159b6c60ae1f08a3d6949 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 16:56:59 +0100 Subject: [PATCH 4/6] Follow the preview into a folder opened in place MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The preview reported each file it stepped to, and the list's cursor followed only a file directly in the folder shown. Previewing a file in a folder opened in the tree and stepping with → left the cursor behind, so ↓ then stepped from the old row, backward. A file anywhere under the folder shown now moves the cursor to its row. The preview's lines are read by Backend::previewSaid, which the test drives. Co-Authored-By: Claude Opus 5.5 --- src/FolderPane.qml | 5 +++++ src/backend.cpp | 37 +++++++++++++++++++++---------------- src/backend.h | 6 ++++++ tests/folio_tests.cpp | 8 ++++++++ 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/src/FolderPane.qml b/src/FolderPane.qml index a679a939..7a377a5e 100644 --- a/src/FolderPane.qml +++ b/src/FolderPane.qml @@ -233,6 +233,11 @@ FocusScope { Connections { target: backend function onSelectRequested(name) { if (view.item) view.item.select(backend.folder.indexOf(name), false) } + function onSelectPathRequested(path) { + const row = backend.folder.indexOfPath(path) + if (view.item && row >= 0) + view.item.select(row, false) + } // Followed now, not later as a re-read is: the preview waits for the // new item before its next arrow. function onStepRequested(direction) { if (view.item) { view.item.stepRow(direction); pane.follow() } } diff --git a/src/backend.cpp b/src/backend.cpp index 0b751237..e9614771 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -41,22 +41,8 @@ Backend::Backend(const QString &home, QObject *parent) }); // The preview reports each file it steps to, and the grid follows. connect(&m_preview, &QProcess::readyReadStandardOutput, this, [this] { - while (m_preview.canReadLine()) { - const QString shown = QString::fromUtf8(m_preview.readLine()).trimmed(); - if (shown.startsWith("step ")) { - // The view moves and sends its new item right away (or - // nothing, at the first or last row); "stepped" after it - // lets the preview take the arrows that came meanwhile. - emit stepRequested(shown.mid(5).toInt() < 0 ? -1 : 1); - if (previewing()) - m_preview.write("stepped\n"); - continue; - } - m_previewed = shown; - const QFileInfo info(shown); - if (info.absolutePath() == path()) - emit selectRequested(info.fileName()); - } + while (m_preview.canReadLine()) + previewSaid(QString::fromUtf8(m_preview.readLine()).trimmed()); }); connect(&m_preview, &QProcess::stateChanged, this, &Backend::previewingChanged); connect(&m_preview, &QProcess::finished, this, [this](int, QProcess::ExitStatus status) { @@ -729,3 +715,22 @@ void Backend::setBusy(const QString &busy) { m_busy = busy; emit busyChanged(); } + +void Backend::previewSaid(const QString &shown) { + if (shown.startsWith("step ")) { + // The view moves and sends its new item right away (or nothing, at + // the first or last row); "stepped" after it lets the preview take + // the arrows that came meanwhile. + emit stepRequested(shown.mid(5).toInt() < 0 ? -1 : 1); + if (previewing()) + m_preview.write("stepped\n"); + return; + } + m_previewed = shown; + // Any file in the folder shown or below it: one in a folder opened in + // place (the list's tree) is a row too, and the cursor goes to it, so + // ↑ and ↓ step from there. + const QString here = path().endsWith('/') ? path() : path() + '/'; + if (shown.startsWith(here)) + emit selectPathRequested(shown); +} diff --git a/src/backend.h b/src/backend.h index 26fb4e8f..4c066234 100644 --- a/src/backend.h +++ b/src/backend.h @@ -112,6 +112,9 @@ class Backend : public QObject { // Space: opens the large preview of a file in its own process, or closes // it when it's already open. Q_INVOKABLE void togglePreview(const QString &path); + // A line from the preview: the file it moved to, or "step -1"/"step 1" + // asking for the row above or below. + void previewSaid(const QString &line); // Ctrl+N: another window, on the folder this one shows. Q_INVOKABLE void newWindow(); // In a file chooser, opening a file picks it (chosen) rather than opening @@ -150,6 +153,9 @@ class Backend : public QObject { void newWindowRequested(const QString &path); void chosen(const QString &path); void selectRequested(const QString &name); + // The preview moved to `path`, in the folder shown or a folder opened in + // place in it: the cursor goes to its row. + void selectPathRequested(const QString &path); // The preview's ↑ or ↓ on a file it can't scroll: move one row in the // folder view, whose layout only this window knows. void stepRequested(int direction); diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index e726765b..c9383cb7 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7357,6 +7357,14 @@ private slots: QTRY_COMPARE_WITH_TIMEOUT(cursor(), home.filePath("files/alpha/z.txt"), 3000); QCOMPARE(folder->get(folder->indexOfPath(home.filePath("files/alpha/z.txt"))).value("selected").toBool(), true); QCOMPARE(folder->selectedCount(), 1); + + // The preview stepping to a file in the opened folder moves the + // cursor to its row, so ↑ and ↓ step from there; one outside the + // folder shown leaves it be. + backend.previewSaid(home.filePath("files/alpha/b.txt")); + QTRY_COMPARE(cursor(), home.filePath("files/alpha/b.txt")); + backend.previewSaid(home.filePath("elsewhere/x.txt")); + QCOMPARE(cursor(), home.filePath("files/alpha/b.txt")); } // Right-click selects the item under the pointer in a scrolled view too, From 45634d0a90810cb75d175f2fdf2b3de08adef0ca Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 17:31:51 +0100 Subject: [PATCH 5/6] Hold the arrows while an untyped file is read too MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A file whose name gives no type is read off the UI thread to learn what it holds, and it may turn out to be a long text. While that read ran, readingText stayed off, so on a slow mount ↑ or ↓ could step past it as if it fit, before its text had appeared. The guard now stays on while such a file's type and possible text are read, as it does for a text whose name says so. Co-Authored-By: Claude Opus 5.5 --- src/previewer.cpp | 3 ++- src/previewer.h | 5 +++-- tests/folio_tests.cpp | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/previewer.cpp b/src/previewer.cpp index b2332ec2..6d6c2468 100644 --- a/src/previewer.cpp +++ b/src/previewer.cpp @@ -277,7 +277,8 @@ void Previewer::setIndex(int index, bool report) { // A file its extension could not name is named by what it holds, read with the rest and kept apart from the listing. const bool unnamed = e.mime == "application/octet-stream"; if (count || text || unnamed) { - m_readingText = text; + // A file its name gave no type may turn out to be a long text. + m_readingText = text || unnamed; auto *watcher = new QFutureWatcher>(this); connect(watcher, &QFutureWatcherBase::finished, this, [this, watcher, generation, unnamed] { watcher->deleteLater(); diff --git a/src/previewer.h b/src/previewer.h index 5d7cb44f..b189df00 100644 --- a/src/previewer.h +++ b/src/previewer.h @@ -32,8 +32,9 @@ class Previewer : public QObject { Q_PROPERTY(QString viewer READ viewer NOTIFY changed) Q_PROPERTY(QString url READ url NOTIFY changed) Q_PROPERTY(QString text READ text NOTIFY changed) - // A text's opening part is still being read: until it's in, its length - // (whether ↑ and ↓ scroll it or step past it) isn't known. + // A text's opening part, or the type of a file its name gave none, is + // still being read: until it's in, whether it's a long text (whether ↑ + // and ↓ scroll it or step past it) isn't known. Q_PROPERTY(bool readingText READ readingText NOTIFY changed) Q_PROPERTY(QString type READ type NOTIFY changed) diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index c9383cb7..8d704935 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7728,6 +7728,14 @@ private slots: QCOMPARE(previewer.text().size(), 4096); previewer.show(dir.filePath("b.png")); QVERIFY(!previewer.readingText()); + + // A file its name gives no type might be a long text too, until + // what it holds has been read. + write(dir.filePath("NOTES"), QByteArray(4096, 'x')); + previewer.show(dir.filePath("NOTES")); + QVERIFY(previewer.readingText()); + QTRY_VERIFY(!previewer.readingText()); + QCOMPARE(previewer.viewer(), QString("text")); } void themeFallsBack() From 9d4f5211e320cc29b02306df18ca854975657500 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Wed, 18 Nov 2026 17:31:51 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Step=20past=20a=20one-page=20PDF=20with=20?= =?UTF-8?q?=E2=86=91=20and=20=E2=86=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The PDF preview has no contentHeight, so the window always took it for something to scroll: ↑ and ↓ turned its pages, and on a PDF of a single page they went nowhere, never on to the item above or below. The PDF preview now says whether it scrolls, which it does with more than one page, and the window asks a view that says so before falling back on its content's height. Co-Authored-By: Claude Opus 5.5 --- src/PdfPreview.qml | 3 +++ src/PreviewWindow.qml | 2 +- tests/folio_tests.cpp | 52 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) diff --git a/src/PdfPreview.qml b/src/PdfPreview.qml index ec095231..e706afa2 100644 --- a/src/PdfPreview.qml +++ b/src/PdfPreview.qml @@ -6,6 +6,9 @@ import QtQuick.Pdf Item { id: pdf + // ↑ and ↓ move between the pages, or with only one, to the next item. + readonly property bool scrolls: doc.pageCount > 1 + function fit() { view.scaleToWidth(Math.min(width - 48, 960), height) } function zoomBy(factor) { view.renderScale = Math.max(0.1, Math.min(10, view.renderScale * factor)) } function scroll(direction) { page(direction) } diff --git a/src/PreviewWindow.qml b/src/PreviewWindow.qml index d704b44b..73543365 100644 --- a/src/PreviewWindow.qml +++ b/src/PreviewWindow.qml @@ -69,7 +69,7 @@ ApplicationWindow { return const v = win.view const scrolls = v && typeof v.scroll === "function" - && (v.contentHeight === undefined || v.contentHeight > v.height + 1) + && (v.scrolls !== undefined ? v.scrolls : v.contentHeight > v.height + 1) if (scrolls) v.scroll(direction) else diff --git a/tests/folio_tests.cpp b/tests/folio_tests.cpp index 8d704935..42dada32 100644 --- a/tests/folio_tests.cpp +++ b/tests/folio_tests.cpp @@ -7738,6 +7738,58 @@ private slots: QCOMPARE(previewer.viewer(), QString("text")); } + void previewStepsPastAOnePagePdf() + { + QTemporaryDir dir; + for (const char *name : {"one.pdf", "two.pdf"}) { + QPdfWriter pdf(dir.filePath(name)); + QPainter painter(&pdf); + if (QByteArray(name) == "two.pdf") + pdf.newPage(); + } + write(dir.filePath("z.png"), "z"); + + Previewer previewer; + previewer.connectToFolio(false); + QSignalSpy reported(&previewer, &Previewer::reported); + previewer.start(dir.filePath("two.pdf"), false, "name"); + Theme theme(dir.filePath("theme")); + Thumbnails thumbnails(dir.filePath("cache"), {dir.filePath("none")}); + QQmlEngine engine; + engine.rootContext()->setContextProperty("theme", &theme); + engine.rootContext()->setContextProperty("translator", QVariantMap{{"language", "en"}}); + engine.rootContext()->setContextProperty("previewer", &previewer); + engine.addImageProvider("thumb", new ThumbnailProvider(&thumbnails)); + QQmlComponent pdf(&engine); + pdf.setData("import QtQuick.Pdf\nPdfDocument {}\n", QUrl()); + if (pdf.isError()) + QSKIP("Qt PDF isn't installed"); + QQmlComponent component(&engine, QUrl("qrc:/PreviewWindow.qml")); + std::unique_ptr window(component.create()); + QVERIFY2(window, qPrintable(component.errorString())); + const auto pages = [&]() -> int { + auto *view = window->property("view").value(); + for (QObject *child : view ? view->children() : QObjectList()) + if (child->property("pageCount").isValid()) + return child->property("pageCount").toInt(); + return -1; + }; + const auto steps = [&] { + int n = 0; + for (const QList &line : reported) + n += line.at(0).toString().startsWith("step "); + return n; + }; + // Pages to turn take ↑ and ↓; a single page lets them move on. + QTRY_COMPARE(pages(), 2); + QMetaObject::invokeMethod(window.get(), "upDown", Q_ARG(QVariant, 1)); + QCOMPARE(steps(), 0); + previewer.show(dir.filePath("one.pdf")); + QTRY_COMPARE(pages(), 1); + QMetaObject::invokeMethod(window.get(), "upDown", Q_ARG(QVariant, 1)); + QCOMPARE(steps(), 1); + } + void themeFallsBack() { QTemporaryDir dir;