Skip to content

Commit a07c87d

Browse files
committed
refactor: boxes: Simplify generic_autocomplete using autocomplete_forms.
This introduces `autocomplete_forms` to simplify the if-elif-else block in `generic_autocomplete`.
1 parent 9867896 commit a07c87d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

zulipterminal/ui_tools/boxes.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,22 @@ def stream_box_view(self, caption: str='', title: str='') -> None:
9696
self.contents = write_box
9797

9898
def generic_autocomplete(self, text: str, state: int) -> Optional[str]:
99+
autocomplete_forms = {
100+
'emojis': self.autocomplete_emojis,
101+
'mentions': self.autocomplete_mentions,
102+
'streams': self.autocomplete_streams,
103+
}
99104
if text.startswith('@_'):
100-
typeahead = self.autocomplete_mentions(text, '@_')
105+
form, prefix_string = 'mentions', '@_'
101106
elif text.startswith('@'):
102-
typeahead = self.autocomplete_mentions(text, '@')
107+
form, prefix_string = 'mentions', '@'
103108
elif text.startswith('#'):
104-
typeahead = self.autocomplete_streams(text, '#')
109+
form, prefix_string = 'streams', '#'
105110
elif text.startswith(':'):
106-
typeahead = self.autocomplete_emojis(text, ':')
111+
form, prefix_string = 'emojis', ':'
107112
else:
108113
return text
114+
typeahead = autocomplete_forms[form](text, prefix_string)
109115

110116
try:
111117
return typeahead[state]

0 commit comments

Comments
 (0)