Skip to content

Commit 5306a21

Browse files
committed
bugfix: view: Fix Zulip crash during search.
This commit fixes a bug which causes Zulip to crash when searching Streams or Topics. This happens because when a search result is empty, log is empty and because an empty ListWalker returns None, it leads to a Type error when setting focus. This is fixed by adding a boolean `in_search_mode` which does not call `get_focus` untill the search is over. Slight reordering was done in `__init__` to fit the boolean in an ideal place w.r.t. readability. Incidentally, the same commit also corrects what the code for `focus_index_before_search` was intended to do. Fixes zulip#923 and Fixes zulip#975
1 parent 424eb98 commit 5306a21

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

zulipterminal/ui_tools/views.py

+17-7
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,17 @@ def __init__(self) -> None:
293293
class StreamsView(urwid.Frame):
294294
def __init__(self, streams_btn_list: List[Any], view: Any) -> None:
295295
self.view = view
296-
self.log = urwid.SimpleFocusListWalker(streams_btn_list)
296+
# Create Stream List Box
297297
self.streams_btn_list = streams_btn_list
298-
self.in_search_mode = False
299-
self.focus_index_before_search = 0
298+
self.log = urwid.SimpleFocusListWalker(streams_btn_list)
300299
list_box = urwid.ListBox(self.log)
300+
# Create Stream Search Box
301301
self.stream_search_box = PanelSearchBox(self,
302302
'SEARCH_STREAMS',
303303
self.update_streams)
304+
self.focus_index_before_search = 0
305+
self.in_search_mode = False
306+
# Create Stream View Frame
304307
super().__init__(list_box, header=urwid.LineBox(
305308
self.stream_search_box, tlcorner='─', tline='', lline='',
306309
trcorner='─', blcorner='─', rline='',
@@ -379,17 +382,21 @@ class TopicsView(urwid.Frame):
379382
def __init__(self, topics_btn_list: List[Any], view: Any,
380383
stream_button: Any) -> None:
381384
self.view = view
382-
self.log = urwid.SimpleFocusListWalker(topics_btn_list)
383-
self.topics_btn_list = topics_btn_list
384385
self.stream_button = stream_button
385-
self.focus_index_before_search = 0
386+
# Create Topic List Box
387+
self.topics_btn_list = topics_btn_list
388+
self.log = urwid.SimpleFocusListWalker(topics_btn_list)
386389
self.list_box = urwid.ListBox(self.log)
390+
# Create Topic Search Box
387391
self.topic_search_box = PanelSearchBox(self,
388392
'SEARCH_TOPICS',
389393
self.update_topics)
394+
self.focus_index_before_search = 0
395+
self.in_search_mode = False
390396
self.header_list = urwid.Pile([self.stream_button,
391397
urwid.Divider('─'),
392398
self.topic_search_box])
399+
# Create Topic View Frame
393400
super().__init__(self.list_box, header=urwid.LineBox(
394401
self.header_list, tlcorner='─', tline='', lline='',
395402
trcorner='─', blcorner='─', rline='',
@@ -456,6 +463,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
456463
self.view.show_left_panel(visible=False)
457464
self.view.body.focus_col = 1
458465
if is_command_key('SEARCH_TOPICS', key):
466+
self.in_search_mode = True
459467
self.set_focus('header')
460468
self.header_list.set_focus(2)
461469
return key
@@ -466,9 +474,11 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
466474
self.set_focus('body')
467475
self.log.set_focus(self.focus_index_before_search)
468476
self.view.controller.update_screen()
477+
self.in_search_mode = False
469478
return key
470479
return_value = super().keypress(size, key)
471-
_, self.focus_index_before_search = self.log.get_focus()
480+
if not self.in_search_mode:
481+
_, self.focus_index_before_search = self.log.get_focus()
472482
return return_value
473483

474484

0 commit comments

Comments
 (0)