diff --git a/meshterm/ui/message_paths_screen.py b/meshterm/ui/message_paths_screen.py index e76549e..0d1d6d9 100644 --- a/meshterm/ui/message_paths_screen.py +++ b/meshterm/ui/message_paths_screen.py @@ -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. diff --git a/meshterm/ui/node_detail_screen.py b/meshterm/ui/node_detail_screen.py index b9a9296..b30b609 100644 --- a/meshterm/ui/node_detail_screen.py +++ b/meshterm/ui/node_detail_screen.py @@ -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: diff --git a/meshterm/ui/path_composer.py b/meshterm/ui/path_composer.py index ea0750c..361a643 100644 --- a/meshterm/ui/path_composer.py +++ b/meshterm/ui/path_composer.py @@ -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: diff --git a/meshterm/ui/tui/screen.py b/meshterm/ui/tui/screen.py index 96735d2..813a811 100644 --- a/meshterm/ui/tui/screen.py +++ b/meshterm/ui/tui/screen.py @@ -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. diff --git a/meshterm/ui/walk_screen.py b/meshterm/ui/walk_screen.py index 620e9f6..70edac4 100644 --- a/meshterm/ui/walk_screen.py +++ b/meshterm/ui/walk_screen.py @@ -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. diff --git a/tests/test_message_paths_screen.py b/tests/test_message_paths_screen.py index 0d8cc50..1b6fd63 100644 --- a/tests/test_message_paths_screen.py +++ b/tests/test_message_paths_screen.py @@ -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 diff --git a/tests/test_node_detail.py b/tests/test_node_detail.py index d401826..2753dc9 100644 --- a/tests/test_node_detail.py +++ b/tests/test_node_detail.py @@ -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.""" diff --git a/tests/test_topology.py b/tests/test_topology.py index d8c72b3..4db3da5 100644 --- a/tests/test_topology.py +++ b/tests/test_topology.py @@ -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 diff --git a/tests/test_walk.py b/tests/test_walk.py index c38f383..6a634a7 100644 --- a/tests/test_walk.py +++ b/tests/test_walk.py @@ -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