Skip to content

Commit

Permalink
boxes: Disable stream change during edit.
Browse files Browse the repository at this point in the history
Fixes zulip#774.
  • Loading branch information
Abhirup-99 committed Feb 17, 2021
1 parent 306a394 commit aacda73
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
2 changes: 1 addition & 1 deletion tests/ui_tools/test_boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,7 +642,7 @@ def test_keypress_typeahead_mode_autocomplete_key(self, mocker, write_box,
('CONTAINER_HEADER', 'HEADER_BOX_EDIT', "stream", True, True,
'CONTAINER_MESSAGE', 'MESSAGE_BOX_BODY'),
('CONTAINER_MESSAGE', 'MESSAGE_BOX_BODY', "stream", True, True,
'CONTAINER_HEADER', 'HEADER_BOX_STREAM'),
'CONTAINER_HEADER', 'HEADER_BOX_TOPIC'),
('CONTAINER_HEADER', 'HEADER_BOX_RECIPIENT', "private", True, False,
'CONTAINER_MESSAGE', 'MESSAGE_BOX_BODY'),
('CONTAINER_MESSAGE', 'MESSAGE_BOX_BODY', "private", True, False,
Expand Down
46 changes: 33 additions & 13 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ def __init__(self, view: Any) -> None:
# Private message recipient text entry, None if stream-box
# or not initialized
self.to_write_box: Optional[ReadlineEdit] = None
self.in_edit_message_box = False
self.edit_caption: Optional[str] = None

# For tracking sending typing status updates
self.send_next_typing_update = datetime.now()
Expand Down Expand Up @@ -208,8 +210,8 @@ def update_recipient_emails(self, write_box: ReadlineEdit) -> None:
write_box.edit_text
)

def stream_box_view(self, stream_id: int, caption: str='', title: str='',
) -> None:
def _stream_view(self, stream_id: int, caption: str='', title: str='',
) -> None:
self.set_editor_mode()
self.stream_id = stream_id
self.recipient_user_ids = self.model.get_other_subscribers_in_stream(
Expand All @@ -221,13 +223,6 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box = ReadlineEdit(edit_text=caption)
self.stream_write_box.enable_autocomplete(
func=self._stream_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box.set_completer_delims("")

self.title_write_box = ReadlineEdit(edit_text=title)
self.title_write_box.enable_autocomplete(
Expand Down Expand Up @@ -259,14 +254,29 @@ def stream_box_view(self, stream_id: int, caption: str='', title: str='',
]
self.contents = write_box

def stream_box_view(self, stream_id: int, caption: str='', title: str='',
) -> None:
self.stream_write_box = ReadlineEdit(
edit_text=caption
)
self.stream_write_box.enable_autocomplete(
func=self._stream_box_autocomplete,
key=primary_key_for_command('AUTOCOMPLETE'),
key_reverse=primary_key_for_command('AUTOCOMPLETE_REVERSE')
)
self.stream_write_box.set_completer_delims("")
self._stream_view(stream_id, caption, title)
# Use and set a callback to set the stream marker
self._set_stream_write_box_style(None, caption)
urwid.connect_signal(self.stream_write_box, 'change',
self._set_stream_write_box_style)

def stream_box_edit_view(self, stream_id: int, caption: str='',
title: str='') -> None:
self.stream_box_view(stream_id, caption, title)
self.in_edit_message_box = True
self.edit_caption = caption
self.stream_write_box = urwid.Text(caption)
self._stream_view(stream_id, caption, title)
self.edit_mode_button = EditModeButton(self.model.controller, 20)

self.header_write_box.widget_list.append(self.edit_mode_button)
Expand Down Expand Up @@ -539,6 +549,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.keypress(size, 'esc')
elif is_command_key('GO_BACK', key):
self.msg_edit_id = None
self.in_edit_message_box = False
self.edit_caption = None
self.msg_body_edit_enabled = True
self.send_stop_typing_status()
self.view.controller.exit_editor_mode()
Expand Down Expand Up @@ -576,8 +588,11 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.focus_position == self.FOCUS_CONTAINER_HEADER:
if self.to_write_box is None:
if header.focus_col == self.FOCUS_HEADER_BOX_STREAM:
stream_name = (header[self.FOCUS_HEADER_BOX_STREAM]
.edit_text)
if not self.in_edit_message_box:
stream_name = (header[self.FOCUS_HEADER_BOX_STREAM]
.edit_text)
else:
stream_name = self.edit_caption
if not self.model.is_valid_stream(stream_name):
invalid_stream_error = (
'Invalid stream name.'
Expand Down Expand Up @@ -635,7 +650,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
else:
self.focus_position = self.FOCUS_CONTAINER_HEADER
if self.to_write_box is None:
header.focus_col = self.FOCUS_HEADER_BOX_STREAM
if self.in_edit_message_box:
header.focus_col = self.FOCUS_HEADER_BOX_TOPIC
else:
header.focus_col = self.FOCUS_HEADER_BOX_STREAM
else:
header.focus_col = self.FOCUS_HEADER_BOX_RECIPIENT

Expand Down Expand Up @@ -1593,6 +1611,8 @@ def valid_char(self, ch: str) -> bool:
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if ((is_command_key('ENTER', key) and self.get_edit_text() == '')
or is_command_key('GO_BACK', key)):
self.in_edit_message_box = False
self.edit_caption = None
self.panel_view.view.controller.exit_editor_mode()
self.reset_search_text()
self.panel_view.set_focus("body")
Expand Down

0 comments on commit aacda73

Please sign in to comment.