Skip to content

Commit

Permalink
view: Adds refocus after Panel search feature to user list.
Browse files Browse the repository at this point in the history
Adds the refocus after Panel search feature present in Stream and
TopicView to the user list as well using the same variable
`self.focus_index_before_search`

Tests amended
  • Loading branch information
Rohitth007 committed Jun 8, 2021
1 parent e5cc513 commit 982a848
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/ui/test_ui_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,7 @@ def test_init(self, right_col_view):
assert right_col_view.view.user_search == right_col_view.user_search
self.thread.Lock.assert_called_with()
assert right_col_view.search_lock == self.thread.Lock()
assert right_col_view.focus_index_before_search == 0
self.super.assert_called_once_with(
right_col_view.users_view(),
header=self.line_box(right_col_view.user_search),
Expand Down Expand Up @@ -1134,7 +1135,13 @@ 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")

list_w = mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker")
right_col_view.body = UsersView(self.view, ["FOO", "foo", "fan", "boo", "BOO"])
right_col_view.set_body(right_col_view.body)

right_col_view.keypress(size, key)
assert right_col_view.focus_index_before_search == list_w().get_focus()[1]
right_col_view.set_focus.assert_called_once_with("header")

@pytest.mark.parametrize("key", keys_for_command("GO_BACK"))
Expand All @@ -1150,6 +1157,9 @@ def test_keypress_GO_BACK(self, right_col_view, mocker, key, widget_size):

right_col_view.set_body.assert_called_once_with(right_col_view.body)
right_col_view.set_focus.assert_called_once_with("body")
right_col_view.body.log.set_focus.assert_called_once_with(
right_col_view.focus_index_before_search
)
assert right_col_view.user_search.reset_search_text.called


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 @@ -659,6 +659,7 @@ def __init__(self, width: int, view: Any) -> None:
self.allow_update_user_list = True
self.search_lock = threading.Lock()
self.empty_search = False
self.focus_index_before_search = 0
super().__init__(self.users_view(), header=search_box)

@asynch
Expand Down Expand Up @@ -756,6 +757,7 @@ def users_view(self, users: Any = None) -> Any:
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if is_command_key("SEARCH_PEOPLE", key):
self.allow_update_user_list = False
self.focus_index_before_search = self.body.log.get_focus()[1]
self.set_focus("header")
return key
elif is_command_key("GO_BACK", key):
Expand All @@ -764,6 +766,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.body = UsersView(self.view.controller, self.users_btn_list)
self.set_body(self.body)
self.set_focus("body")
self.body.log.set_focus(self.focus_index_before_search)
self.view.controller.update_screen()
return key
elif is_command_key("GO_LEFT", key):
Expand Down

0 comments on commit 982a848

Please sign in to comment.