From 0143d9bacce510ef6b38afeda36e51550a5b2681 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Fri, 24 Jul 2026 15:25:07 -0700 Subject: [PATCH] Clear stale reply context in draw_text_field function and add corresponding test --- contact/ui/contact_ui.py | 12 ++++++++---- tests/test_contact_ui.py | 9 +++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/contact/ui/contact_ui.py b/contact/ui/contact_ui.py index 4a61d7f..b4b5062 100644 --- a/contact/ui/contact_ui.py +++ b/contact/ui/contact_ui.py @@ -1675,21 +1675,25 @@ def remove_notification(channel_number: int) -> None: def draw_text_field(win: curses.window, text: str, color: int) -> None: win.border() + height, width = win.getmaxyx() # Put a small hint in the border of the message entry field. # We key off the "Message:" prompt to avoid affecting other bordered fields. if isinstance(text, str) and text.startswith("Message:"): hint = " Ctrl+K Help " - h, w = win.getmaxyx() - x = max(2, w - len(hint) - 2) + x = max(2, width - len(hint) - 2) try: win.addstr(0, x, hint, get_color("commands")) except curses.error: pass - # Draw the actual field text + # Clear the row before redrawing. Reply context can be longer than the + # next value (or empty after Ctrl+R cancels it), so simply overwriting the + # new text leaves trailing characters from the old context on screen. try: - win.addstr(1, 1, text, color) + if height > 2 and width > 2: + win.addstr(1, 1, " " * (width - 2), color) + win.addstr(1, 1, text[: max(0, width - 2)], color) except curses.error: pass diff --git a/tests/test_contact_ui.py b/tests/test_contact_ui.py index 13c8dad..366a167 100644 --- a/tests/test_contact_ui.py +++ b/tests/test_contact_ui.py @@ -152,6 +152,15 @@ class ContactUiTests(unittest.TestCase): self.assertEqual(ui_state.reply_context, "") self.assertFalse(ui_state.reply_id_unavailable) + def test_draw_text_field_clears_stale_reply_context(self) -> None: + win = mock.Mock() + win.getmaxyx.return_value = (3, 30) + + contact_ui.draw_text_field(win, "Message: ", 1) + + self.assertIn(mock.call(1, 1, " " * 28, 1), win.addstr.call_args_list) + self.assertIn(mock.call(1, 1, "Message: ", 1), win.addstr.call_args_list) + def test_handle_ctrl_r_shows_context_when_message_id_is_unavailable(self) -> None: ui_state.current_window = 1 ui_state.channel_list = ["Primary"]