36
36
)
37
37
from zulipterminal .config .ui_sizes import LEFT_WIDTH
38
38
from zulipterminal .helper import (
39
+ SearchStatus ,
39
40
TidiedUserInfo ,
40
41
asynch ,
41
42
match_emoji ,
@@ -335,7 +336,7 @@ def __init__(self, streams_btn_list: List[Any], view: Any) -> None:
335
336
),
336
337
)
337
338
self .search_lock = threading .Lock ()
338
- self .empty_search = False
339
+ self .search_status = SearchStatus . DEFAULT
339
340
340
341
@asynch
341
342
def update_streams (self , search_box : Any , new_text : str ) -> None :
@@ -352,7 +353,11 @@ def update_streams(self, search_box: Any, new_text: str) -> None:
352
353
)[0 ]
353
354
354
355
streams_display_num = len (streams_display )
355
- self .empty_search = streams_display_num == 0
356
+ self .search_status = (
357
+ SearchStatus .EMPTY
358
+ if streams_display_num == 0
359
+ else SearchStatus .FILTERED
360
+ )
356
361
357
362
# Add a divider to separate pinned streams from the rest.
358
363
pinned_stream_names = [
@@ -371,7 +376,7 @@ def update_streams(self, search_box: Any, new_text: str) -> None:
371
376
streams_display .insert (first_unpinned_index , StreamsViewDivider ())
372
377
373
378
self .log .clear ()
374
- if not self .empty_search :
379
+ if self .search_status == SearchStatus . FILTERED :
375
380
self .log .extend (streams_display )
376
381
else :
377
382
self .log .extend ([self .stream_search_box .search_error ])
@@ -404,6 +409,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
404
409
self .log .extend (self .streams_btn_list )
405
410
self .set_focus ("body" )
406
411
self .log .set_focus (self .focus_index_before_search )
412
+ self .search_status = SearchStatus .DEFAULT
407
413
self .view .controller .update_screen ()
408
414
return key
409
415
return super ().keypress (size , key )
@@ -436,7 +442,7 @@ def __init__(
436
442
header = self .header_list ,
437
443
)
438
444
self .search_lock = threading .Lock ()
439
- self .empty_search = False
445
+ self .search_status = SearchStatus . DEFAULT
440
446
441
447
def _focus_position_for_topic_name (self ) -> int :
442
448
saved_topic_state = self .view .saved_topic_in_stream_id (
@@ -461,10 +467,14 @@ def update_topics(self, search_box: Any, new_text: str) -> None:
461
467
for topic in self .topics_btn_list .copy ()
462
468
if new_text in topic .topic_name .lower ()
463
469
]
464
- self .empty_search = len (topics_to_display ) == 0
470
+ self .search_status = (
471
+ SearchStatus .EMPTY
472
+ if len (topics_to_display ) == 0
473
+ else SearchStatus .FILTERED
474
+ )
465
475
466
476
self .log .clear ()
467
- if not self .empty_search :
477
+ if self .search_status == SearchStatus . FILTERED :
468
478
self .log .extend (topics_to_display )
469
479
else :
470
480
self .log .extend ([self .topic_search_box .search_error ])
@@ -524,6 +534,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
524
534
self .log .extend (self .topics_btn_list )
525
535
self .set_focus ("body" )
526
536
self .log .set_focus (self .focus_index_before_search )
537
+ self .search_status = SearchStatus .DEFAULT
527
538
self .view .controller .update_screen ()
528
539
return key
529
540
return super ().keypress (size , key )
@@ -665,7 +676,7 @@ def __init__(self, view: Any) -> None:
665
676
666
677
self .allow_update_user_list = True
667
678
self .search_lock = threading .Lock ()
668
- self .empty_search = False
679
+ self .search_status = SearchStatus . DEFAULT
669
680
super ().__init__ (self .users_view (), header = search_box )
670
681
671
682
@asynch
@@ -706,10 +717,12 @@ def update_user_list(
706
717
else :
707
718
users_display = users
708
719
709
- self .empty_search = len (users_display ) == 0
720
+ self .search_status = (
721
+ SearchStatus .EMPTY if len (users_display ) == 0 else SearchStatus .FILTERED
722
+ )
710
723
711
724
# FIXME Update log directly?
712
- if not self .empty_search :
725
+ if self .search_status != SearchStatus . EMPTY :
713
726
self .body = self .users_view (users_display )
714
727
else :
715
728
self .body = UsersView (
@@ -765,6 +778,7 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
765
778
self .body = UsersView (self .view .controller , self .users_btn_list )
766
779
self .set_body (self .body )
767
780
self .set_focus ("body" )
781
+ self .search_status = SearchStatus .DEFAULT
768
782
self .view .controller .update_screen ()
769
783
return key
770
784
elif is_command_key ("GO_LEFT" , key ):
@@ -2029,7 +2043,7 @@ def __init__(
2029
2043
search_box = urwid .Pile (
2030
2044
[self .emoji_search , urwid .Divider (SECTION_DIVIDER_LINE )]
2031
2045
)
2032
- self .empty_search = False
2046
+ self .search_status = SearchStatus . DEFAULT
2033
2047
self .search_lock = threading .Lock ()
2034
2048
super ().__init__ (
2035
2049
controller ,
@@ -2075,10 +2089,14 @@ def update_emoji_list(
2075
2089
else :
2076
2090
self .emojis_display = self .emoji_buttons
2077
2091
2078
- self .empty_search = len (self .emojis_display ) == 0
2092
+ self .search_status = (
2093
+ SearchStatus .EMPTY
2094
+ if len (self .emojis_display ) == 0
2095
+ else SearchStatus .FILTERED
2096
+ )
2079
2097
2080
2098
body_content = self .emojis_display
2081
- if self .empty_search :
2099
+ if self .search_status == SearchStatus . EMPTY :
2082
2100
body_content = [self .emoji_search .search_error ]
2083
2101
2084
2102
self .contents ["body" ] = (
@@ -2152,5 +2170,6 @@ def keypress(self, size: urwid_Size, key: str) -> str:
2152
2170
self .emoji_search .reset_search_text ()
2153
2171
self .controller .exit_editor_mode ()
2154
2172
self .controller .exit_popup ()
2173
+ self .search_status = SearchStatus .DEFAULT
2155
2174
return key
2156
2175
return super ().keypress (size , key )
0 commit comments