Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions tests/ui/test_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,6 @@ def test_keypress_autohide_users(self, view, mocker, autohide, key, widget_size)

view.users_view.keypress.assert_called_once_with(size, key)
assert view.body.focus_position == 2
view.user_search.set_edit_text.assert_called_once_with("")
view.controller.enter_editor_mode_with.assert_called_once_with(view.user_search)

@pytest.mark.parametrize("key", keys_for_command("SEARCH_STREAMS"))
Expand All @@ -324,7 +323,6 @@ def test_keypress_autohide_streams(self, view, mocker, autohide, key, widget_siz

view.left_panel.keypress.assert_called_once_with(size, key)
assert view.body.focus_position == 0
view.stream_w.stream_search_box.set_edit_text.assert_called_once_with("")
view.controller.enter_editor_mode_with.assert_called_once_with(
view.stream_w.stream_search_box
)
Expand Down
6 changes: 6 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -568,13 +568,15 @@ def test_mouse_event(self, mocker, stream_view, widget_size):
def test_keypress_SEARCH_STREAMS(self, mocker, stream_view, key, widget_size):
size = widget_size(stream_view)
mocker.patch.object(stream_view, "set_focus")
mocker.patch.object(stream_view.stream_search_box, "set_caption")
stream_view.log.extend(["FOO", "foo", "fan", "boo", "BOO"])
stream_view.log.set_focus(3)

stream_view.keypress(size, key)

assert stream_view.focus_index_before_search == 3
stream_view.set_focus.assert_called_once_with("header")
stream_view.stream_search_box.set_caption.assert_called_once_with(" ")

@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
def test_keypress_GO_BACK(self, mocker, stream_view, key, widget_size):
Expand Down Expand Up @@ -696,6 +698,7 @@ def test_update_topics_list(
def test_keypress_SEARCH_TOPICS(self, mocker, topic_view, key, widget_size):
size = widget_size(topic_view)
mocker.patch(VIEWS + ".TopicsView.set_focus")
mocker.patch.object(topic_view.topic_search_box, "set_caption")
topic_view.log.extend(["FOO", "foo", "fan", "boo", "BOO"])
topic_view.log.set_focus(3)

Expand All @@ -704,6 +707,7 @@ def test_keypress_SEARCH_TOPICS(self, mocker, topic_view, key, widget_size):
topic_view.set_focus.assert_called_once_with("header")
topic_view.header_list.set_focus.assert_called_once_with(2)
assert topic_view.focus_index_before_search == 3
topic_view.topic_search_box.set_caption.assert_called_once_with(" ")

@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
def test_keypress_GO_BACK(self, mocker, topic_view, key, widget_size):
Expand Down Expand Up @@ -1121,8 +1125,10 @@ def test_users_view(
def test_keypress_SEARCH_PEOPLE(self, right_col_view, mocker, key, widget_size):
size = widget_size(right_col_view)
mocker.patch(VIEWS + ".RightColumnView.set_focus")
mocker.patch.object(right_col_view.user_search, "set_caption")
right_col_view.keypress(size, key)
right_col_view.set_focus.assert_called_once_with("header")
right_col_view.user_search.set_caption.assert_called_once_with(" ")

@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
def test_keypress_GO_BACK(self, right_col_view, mocker, key, widget_size):
Expand Down
16 changes: 8 additions & 8 deletions tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1247,7 +1247,7 @@ def test_write_box_header_contents(


class TestPanelSearchBox:
search_caption = "Search Results "
search_caption = " Search Results \n > "

@pytest.fixture
def panel_search_box(self, mocker):
Expand All @@ -1258,18 +1258,18 @@ def panel_search_box(self, mocker):
return PanelSearchBox(panel_view, "UNTESTED_TOKEN", update_func)

def test_init(self, panel_search_box):
assert panel_search_box.search_text == "Search [X]: "
assert panel_search_box.caption == ""
assert panel_search_box.edit_text == panel_search_box.search_text
assert panel_search_box.search_text == " Search [X]: "
assert panel_search_box.caption == panel_search_box.search_text
assert panel_search_box.edit_text == ""

def test_reset_search_text(self, panel_search_box):
panel_search_box.set_caption(self.search_caption)
panel_search_box.edit_text = "key words"

panel_search_box.reset_search_text()

assert panel_search_box.caption == ""
assert panel_search_box.edit_text == panel_search_box.search_text
assert panel_search_box.caption == panel_search_box.search_text
assert panel_search_box.edit_text == ""

@pytest.mark.parametrize(
"search_text, entered_string, expected_result",
Expand Down Expand Up @@ -1345,8 +1345,8 @@ def test_keypress_GO_BACK(self, panel_search_box, back_key, widget_size):
panel_search_box.keypress(size, back_key)

# Reset display
assert panel_search_box.caption == ""
assert panel_search_box.edit_text == panel_search_box.search_text
assert panel_search_box.caption == panel_search_box.search_text
assert panel_search_box.edit_text == ""

# Leave editor mode
panel_view.view.controller.exit_editor_mode.assert_called_once_with()
Expand Down
2 changes: 0 additions & 2 deletions zulipterminal/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
self.users_view.keypress(size, "w")
self.show_left_panel(visible=False)
self.show_right_panel(visible=True)
self.user_search.set_edit_text("")
self.controller.enter_editor_mode_with(self.user_search)
return key
elif is_command_key("SEARCH_STREAMS", key) or is_command_key(
Expand All @@ -240,7 +239,6 @@ def keypress(self, size: urwid_Box, key: str) -> Optional[str]:
search_box = self.topic_w.topic_search_box
else:
search_box = self.stream_w.stream_search_box
search_box.set_edit_text("")
self.controller.enter_editor_mode_with(search_box)
return key
elif is_command_key("OPEN_DRAFT", key):
Expand Down
10 changes: 5 additions & 5 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1806,16 +1806,16 @@ def __init__(
) -> None:
self.panel_view = panel_view
self.search_command = search_command
self.search_text = f"Search [{', '.join(keys_for_command(search_command))}]: "
self.search_text = f" Search [{', '.join(keys_for_command(search_command))}]: "
self.search_error = urwid.AttrMap(
urwid.Text([" ", INVALID_MARKER, " No Results"]), "search_error"
)
urwid.connect_signal(self, "change", update_function)
super().__init__(caption="", edit_text=self.search_text)
super().__init__(caption=self.search_text, edit_text="")

def reset_search_text(self) -> None:
self.set_caption("")
self.set_edit_text(self.search_text)
self.set_caption(self.search_text)
self.set_edit_text("")

def valid_char(self, ch: str) -> bool:
# This method 'strips' leading space *before* entering it in the box
Expand All @@ -1841,7 +1841,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.panel_view.keypress(size, "esc")
elif is_command_key("ENTER", key) and not self.panel_view.empty_search:
self.panel_view.view.controller.exit_editor_mode()
self.set_caption([("filter_results", "Search Results"), " "])
self.set_caption([("filter_results", " Search Results \n"), " > "])
self.panel_view.set_focus("body")
if hasattr(self.panel_view, "log"):
self.panel_view.body.set_focus(0)
Expand Down
3 changes: 3 additions & 0 deletions zulipterminal/ui_tools/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("SEARCH_STREAMS", key):
_, self.focus_index_before_search = self.log.get_focus()
self.set_focus("header")
self.stream_search_box.set_caption(" ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding an extra " " in a method that overrides urwid's set_caption method in PanelSearchBox instead?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was instead thinking, during the Panel refactor I could group this and 1 other common line into a function call enter_search_mode inside PanelSearchBox

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a good function to add during the first commit - it avoids spreading general set_caption calls through the code, which may also be used for other things, as well as providing a central place for this kind of change - and it's easy to grep for a unique name :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@preetmishra @neiljp Previously, the other common line that I was talking about was enter_editor_mode but now that I see that enter_editor_mode would be removed after the keypress refactor and set_caption would be called only once anyway after the Panel refactor, I don't think this needs to be moved into PanelSearchBox using enter_search_mode or similar.

return key
elif is_command_key("GO_BACK", key):
self.stream_search_box.reset_search_text()
Expand Down Expand Up @@ -474,6 +475,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
_, self.focus_index_before_search = self.log.get_focus()
self.set_focus("header")
self.header_list.set_focus(2)
self.topic_search_box.set_caption(" ")
return key
elif is_command_key("GO_BACK", key):
self.topic_search_box.reset_search_text()
Expand Down Expand Up @@ -748,6 +750,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("SEARCH_PEOPLE", key):
self.allow_update_user_list = False
self.set_focus("header")
self.user_search.set_caption(" ")
return key
elif is_command_key("GO_BACK", key):
self.user_search.reset_search_text()
Expand Down