Browser: keep the file list live (re-read on change, re-sort, no idle frames)

The browser list was cached: files added/removed/renamed, or whose mtime
changed, did not show up (and did not re-sort) until the user navigated
away and back in. In particular, opening a file and returning showed a
stale list — a new file created elsewhere only appeared after navigating
up and back down.

The browser now re-reads the current directory while it is on screen:

- A short (~1 s) timer re-reads the visible directory so external changes
  (including inbound syncs) appear live, re-sorted in the current sort
  mode. A landing re-index repopulates the visible+prefetch pages
  synchronously (no flicker), preserves the scroll offset, and re-filters
  an active search without a scroll jump.
- Returning to the browser from the editor triggers one immediate re-read
  so the list is current the moment you land back.
- Bounded to one read per directory: a refresh while a read of the same
  directory is in flight coalesces, and a stale result for a directory the
  user has since left is dropped rather than clobbering the current view.
- A failed background refresh keeps the last good view (the next tick
  retries); a failed navigation still recovers to the previous directory.
- Change detection: a refresh that finds the directory unchanged rebuilds
  nothing and emits no frame, preserving the event-driven emission
  contract (TestNoFramesWhileIdle_Browser) while the browser idles.

Verified on-device: external add while sitting in the browser appears and
re-sorts to the top within ~1 s; an external add+remove made while in the
editor is reflected immediately on return; an external delete drops the
row within ~1 s.
This commit is contained in:
gmp
2026-09-02 18:23:16 -04:00
parent 5e40378072
commit 16740b0de0
7 changed files with 454 additions and 45 deletions
+17
View File
@@ -544,6 +544,23 @@ Only the visible byte range is shaped and drawn each frame:
- The browser renders via `ListView`/`ListItem` elements; rows carry
`Interaction` handlers that send channel requests (tap) or mutate state
directly when the handler runs on the owner (scroll).
- **Live refresh.** While the browser page is on screen, the current directory
is re-read on a short timer (≈1 s) so external changes — files added,
removed, renamed, or mtime-changed (including inbound syncs) — appear live,
re-sorted in the *current* sort mode. Invariant: **a refresh that finds the
directory unchanged rebuilds nothing and emits no frame**, so the
event-driven emission contract (§2; `TestNoFramesWhileIdle_Browser`) still
holds while the browser idles. A landing (re)index is applied in place: the
visible+prefetch pages are repopulated synchronously from the fresh index
(no async gap / flicker), the scroll offset is preserved then clamped, and an
active search is re-filtered without a scroll jump. Bounded to **one read per
directory**: a refresh requested while a read of the same directory is in
flight coalesces (skips), and a stale result for a directory the user has
since left is dropped rather than clobbering the current view. A failed
*refresh* keeps the last good view (the next tick retries); a failed
*navigation* still recovers to the previous directory. Returning to the
browser from the editor triggers one immediate refresh so the list is current
on the frame you land back, not one tick later.
## 8. Render pipeline (`internal/ui`)