diff --git a/meshterm/ui/chat.py b/meshterm/ui/chat.py index 76ebae9..ee4f041 100644 --- a/meshterm/ui/chat.py +++ b/meshterm/ui/chat.py @@ -411,7 +411,12 @@ class ChatScreen(Screen): header = self._group_header(sender, is_self=message.outbound) lines += render_lines(header, width) if selected: - self._selected_line = len(lines) + # The first message owns the head of the transcript: nothing precedes + # its day divider, so its pick anchors at line 0 rather than at its own + # body. Anchoring on the body left the view scrolled two lines in at the + # very top — the divider only pinned, the sender chip gone, and the + # title bar's ↑ lit over a transcript with nothing above it. + self._selected_line = 0 if idx == 0 else len(lines) lines += self._body_lines(body, message, width, selected=selected) prev_group, prev_day = group, day ids.append(id(message)) diff --git a/tests/test_chat.py b/tests/test_chat.py index 752ed55..95c8503 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -1229,6 +1229,26 @@ def test_chat_frame_pins_a_day_divider_when_stuck_to_the_newest() -> None: assert above is True # and the frame flags there's more above the pin +def test_chat_top_of_transcript_clears_the_more_above_flag() -> None: + """Picking the oldest message scrolls the head of the transcript into view. + + The first message's pick anchors at line 0, so the frame lands on offset 0: its day + divider and sender chip are real rows again instead of a pin over a hidden line, and + the title bar's clip arrow goes dim because there genuinely is nothing above. + """ + from meshterm.ui.tui import frame + + screen = _screen(_StubSession(), send=None, messages=_two_day_messages()) + lines = screen.render_body(60) + screen.handle("ctrl_home") # back to the oldest message + lines = screen.render_body(60) + visible, above, below = frame._visible_slice(screen, lines, 6) + + assert screen.scroll == 0 + assert above is False and below is True + assert _strip_ansi(visible[0]).strip().startswith("──") # the head, drawn not pinned + + def test_chat_home_end_and_word_keys_move_the_compose_cursor() -> None: """In a chat, Home/End and Ctrl+←/→ act on the compose line, not the transcript scroll.""" screen = _screen(_StubSession(), send=None, messages=_two_day_messages())