Skip to content

Commit 982a848

Browse files
committed
view: Adds refocus after Panel search feature to user list.
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
1 parent e5cc513 commit 982a848

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

tests/ui/test_ui_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,7 @@ def test_init(self, right_col_view):
10431043
assert right_col_view.view.user_search == right_col_view.user_search
10441044
self.thread.Lock.assert_called_with()
10451045
assert right_col_view.search_lock == self.thread.Lock()
1046+
assert right_col_view.focus_index_before_search == 0
10461047
self.super.assert_called_once_with(
10471048
right_col_view.users_view(),
10481049
header=self.line_box(right_col_view.user_search),
@@ -1134,7 +1135,13 @@ def test_users_view(
11341135
def test_keypress_SEARCH_PEOPLE(self, right_col_view, mocker, key, widget_size):
11351136
size = widget_size(right_col_view)
11361137
mocker.patch(VIEWS + ".RightColumnView.set_focus")
1138+
1139+
list_w = mocker.patch(VIEWS + ".urwid.SimpleFocusListWalker")
1140+
right_col_view.body = UsersView(self.view, ["FOO", "foo", "fan", "boo", "BOO"])
1141+
right_col_view.set_body(right_col_view.body)
1142+
11371143
right_col_view.keypress(size, key)
1144+
assert right_col_view.focus_index_before_search == list_w().get_focus()[1]
11381145
right_col_view.set_focus.assert_called_once_with("header")
11391146

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

11511158
right_col_view.set_body.assert_called_once_with(right_col_view.body)
11521159
right_col_view.set_focus.assert_called_once_with("body")
1160+
right_col_view.body.log.set_focus.assert_called_once_with(
1161+
right_col_view.focus_index_before_search
1162+
)
11531163
assert right_col_view.user_search.reset_search_text.called
11541164

11551165

zulipterminal/ui_tools/views.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,7 @@ def __init__(self, width: int, view: Any) -> None:
659659
self.allow_update_user_list = True
660660
self.search_lock = threading.Lock()
661661
self.empty_search = False
662+
self.focus_index_before_search = 0
662663
super().__init__(self.users_view(), header=search_box)
663664

664665
@asynch
@@ -756,6 +757,7 @@ def users_view(self, users: Any = None) -> Any:
756757
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
757758
if is_command_key("SEARCH_PEOPLE", key):
758759
self.allow_update_user_list = False
760+
self.focus_index_before_search = self.body.log.get_focus()[1]
759761
self.set_focus("header")
760762
return key
761763
elif is_command_key("GO_BACK", key):
@@ -764,6 +766,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
764766
self.body = UsersView(self.view.controller, self.users_btn_list)
765767
self.set_body(self.body)
766768
self.set_focus("body")
769+
self.body.log.set_focus(self.focus_index_before_search)
767770
self.view.controller.update_screen()
768771
return key
769772
elif is_command_key("GO_LEFT", key):

0 commit comments

Comments
 (0)