Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boxes: Disable stream change during edit. #870

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Abhirup-99 marked this conversation as resolved.
Show resolved Hide resolved
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:
Abhirup-99 marked this conversation as resolved.
Show resolved Hide resolved
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