A windowed list stops at its ends

Four screens hand their rows to a ListWindow and let the highlight drive it:
the mesh walk's links, the path composer's suggestions, the node detail's
routes, and Message paths' arrivals. All four wrapped — ↓ off the last row
landed on the first — and in a windowed list that is not one step. The window
follows the highlight, so the wrap hauls the whole list from the tail back to
the head and flips both edge markers on the way: it reads as the screen
changing under the reader rather than as a move they made (JP, 2026-09-04).

All four clamp now, the way the live feed's cursor already did and the way a
grouped select list does with `wrap=False`. Held-down arrows settle at an end.
The rule is written down where the pattern lives, on `ListWindow` itself —
each screen owns its own cursor, so the class can state it but not enforce it.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Opus 5 committed 2026-09-04 02:20:20 -04:00
1 parent 0eb9845cd9
commit a5fd4357f1
9 files changed
+95 -8

No files matched your search

+5 -2
View File
@@ -194,11 +194,14 @@ class MessagePathsScreen(Screen):
def handle(self, action: str, data: str = "") -> None:
"""Move the selection, shift the selected line sideways, or dismiss."""
rows = len(self._arrivals)
# Both ends clamp rather than wrap: the arrivals scroll inside a window (see
# ListWindow), and a highlight that jumped from the last arrival to the first would
# take the window with it — the one move that looks like the screen changed under you.
if action == "up" and rows:
self._index = (self._index - 1) % rows
self._index = max(0, self._index - 1)
self._hshift = 0
elif action == "down" and rows:
self._index = (self._index + 1) % rows
self._index = min(rows - 1, self._index + 1)
self._hshift = 0
elif action == "pageup" and rows:
# A windowful of *arrivals*, not of body lines: the list is what moves.
+6 -2
View File
@@ -603,11 +603,15 @@ class NodeDetailScreen(Screen):
self._switch_tab(-1)
elif action == "up":
if n:
self._row_index = (self._row_index - 1) % n
# Both ends clamp rather than wrap: the route rows scroll inside a
# window (see ListWindow), and a highlight that jumped end to end would
# take the window with it — the one move that looks like the screen
# changed under you.
self._row_index = max(0, self._row_index - 1)
self._sync_route_sel(focus)
elif action == "down":
if n:
self._row_index = (self._row_index + 1) % n
self._row_index = min(n - 1, self._row_index + 1)
self._sync_route_sel(focus)
elif action == "pageup":
if n:
+5 -2
View File
@@ -702,10 +702,13 @@ class PathComposerScreen(Screen):
def handle(self, action: str, data: str = "") -> None:
"""Move the cursors, edit the entry, add/remove hops, or commit/cancel."""
rows = self._rows()
# Both ends clamp rather than wrap: this list scrolls inside a window (see
# ListWindow), and a highlight that jumped from the tail to the head would take the
# whole window with it — the one move that looks like the screen changed under you.
if action == "up" and rows:
self._index = (self._index - 1) % len(rows)
self._index = max(0, self._index - 1)
elif action == "down" and rows:
self._index = (self._index + 1) % len(rows)
self._index = min(len(rows) - 1, self._index + 1)
elif action == "pageup" and rows:
self._index = max(0, self._index - self._list.page)
elif action == "pagedown" and rows:
+9
View File
@@ -443,6 +443,15 @@ class ListWindow:
that side, and the settled content capacity is remembered as :attr:`page`, the
stride a PgUp/PgDn should move by.
A highlight over such a list **clamps at both ends rather than wrapping** (as
:class:`~meshterm.ui.tui.select.SelectScreen` does with ``wrap=False``, and for a
sharper reason): the window follows the highlight, so a ↓ off the last row would not
merely move the pointer — it would haul the whole window back to the head, flipping
the edge markers as it went, which reads as the screen changing under the reader
rather than as one step. Held-down arrows settle at an end instead (JP, 2026-09-04).
Each screen owns its own cursor, so this is a rule its ``handle`` keeps, not something
this class can enforce.
Attributes:
top: First list row the window shows (clamped by :meth:`fit` each paint).
page: Rows the window carried on the last :meth:`fit` — the paging stride.
+5 -2
View File
@@ -443,9 +443,12 @@ class WalkScreen(Screen):
self.resolve(None)
return
elif action == "up" and rows:
self._index = (self._index - 1) % len(rows)
# Both ends clamp rather than wrap: the list scrolls inside a window (see
# ListWindow), and a highlight that jumped end to end would take the window
# with it — the one move that looks like the screen changed under you.
self._index = max(0, self._index - 1)
elif action == "down" and rows:
self._index = (self._index + 1) % len(rows)
self._index = min(len(rows) - 1, self._index + 1)
elif action == "pageup" and rows:
# The highlight pages by one list windowful: the window follows the
# highlight, so paging the view without it would just snap straight back.
+13
View File
@@ -384,3 +384,16 @@ def test_a_short_list_advertises_no_paging() -> None:
screen.render_body(72)
assert "PgUp/PgDn" not in screen.footer_hint
assert "more" not in _plain(screen.render_body(72))
def test_the_selection_clamps_at_both_ends() -> None:
"""↑ on the first arrival and ↓ on the last stay put: the window follows the highlight,
so a wrap would haul the whole list end to end instead of moving one row."""
screen = _screen(_many(6))
screen.note_viewport(24)
screen.render_body(72)
screen.handle("up")
assert screen._index == 0
for _ in range(10):
screen.handle("down")
assert screen._index == 5
+22
View File
@@ -1006,6 +1006,28 @@ def test_node_detail_route_list_windows_inside_the_page() -> None:
assert "route 11" in _plain(lines) and screen.cursor_line() is not None
def test_node_detail_route_cursor_clamps_at_both_ends() -> None:
"""The windowed route list does not wrap: ↑ on the first row and ↓ past the last stay
where they are, rather than hauling the window end to end."""
routes = _RoutesView(
routes=[
_Route(draw=(f"{i:x}{i:x}" * 6,), spec=f"s{i}", path=Text(f"route {i}"), context=Text(""))
for i in range(12)
],
glyph_of=lambda n: ("●", "#ffffff"),
label_of=lambda n: n[:2],
label_rgb_of=lambda n: (200, 200, 200),
)
screen = _screen(routes=routes, tabs=[_Tab("Routes", "routes")])
screen.note_viewport(30)
screen.render_body(72)
screen.handle("up")
assert screen._row_index == 0
for _ in range(20):
screen.handle("down")
assert screen._row_index == 11
def test_fit_blocks_walks_wrapped_rows_into_view() -> None:
"""The variable-height fit keeps whole blocks, spends marker lines only when rows hide,
and walks the window down to the cursor's row."""
+14
View File
@@ -976,3 +976,17 @@ def test_a_stub_whose_only_link_was_its_owner_takes_the_owner_out_with_it() -> N
topo._merge_node("a1", "a1b2c3d4e5f6", adjacency=adjacency)
assert topo._links == {}
assert adjacency == {}
def test_composer_row_cursor_clamps_at_both_ends() -> None:
"""The windowed suggestion list does not wrap: ↑ on the first row and ↓ past the last
stay where they are, rather than hauling the window end to end."""
walks = [_traced(("3d", 12.0), ("f2", -5.0), ("3d", -5.5), (None, 12.0))]
screen = _composer(_topo(trace_paths=walks))
screen.render_body(90)
last = len(screen._rows()) - 1
screen.handle("up")
assert screen._index == 0
for _ in range(last + 5):
screen.handle("down")
assert screen._index == last
+16
View File
@@ -937,3 +937,19 @@ def test_walk_collapsed_stand_in_wears_the_selection_white() -> None:
row = next(line for line in canvas if screen._label(target) in _plain([line]))
assert _code((255, 255, 255)) in row # the same white a drawn marker's selection takes
assert _code(screen._label_rgb(target)) not in row
def test_walk_link_cursor_clamps_at_both_ends() -> None:
"""The windowed link list does not wrap: ↑ on the first row and ↓ past the last stay
where they are, rather than hauling the window end to end."""
screen = WalkScreen(
session=_FakeSession(), topo=_hub_topo(14), contacts={}, self_label="us"
)
screen.note_viewport(20)
screen.render_body(80)
last = len(screen._rows()) - 1
screen.handle("up")
assert screen._index == 0
for _ in range(last + 5):
screen.handle("down")
assert screen._index == last