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.

Co-authored-by: Abhirup-99 <[email protected]>
  • Loading branch information
neiljp and Abhirup-99 committed Mar 7, 2022
1 parent c1c6058 commit 7423415
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 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 @@ -1412,7 +1412,7 @@ def test_keypress_typeahead_mode_autocomplete_key(
True,
True,
"CONTAINER_HEADER",
"HEADER_BOX_STREAM",
"HEADER_BOX_TOPIC",
id="edit_box-message_to_stream_name_box",
),
case(
Expand Down
45 changes: 33 additions & 12 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ def __init__(self, view: Any) -> None:
# Determines if the message body (content) can be edited
self.msg_body_edit_enabled: bool

# New state during message editing to avoid stream editing
self.in_edit_message_box = False
self.edit_caption: Optional[str] = None

self.is_in_typeahead_mode = False

# Set to int for stream box only
Expand Down Expand Up @@ -358,16 +362,6 @@ def _setup_common_stream_compose(
)
self.msg_write_box.set_completer_delims(DELIMS_MESSAGE_COMPOSE)

self.stream_write_box = ReadlineEdit(
edit_text=caption, max_char=self.model.max_stream_name_length
)
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, max_char=self.model.max_topic_length
)
Expand Down Expand Up @@ -416,6 +410,15 @@ def stream_box_view(
caption: str = "",
title: str = "",
) -> None:
self.stream_write_box = ReadlineEdit(
edit_text=caption, max_char=self.model.max_stream_name_length
)
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._setup_common_stream_compose(stream_id, caption, title)

# Use and set a callback to set the stream marker
Expand All @@ -427,6 +430,10 @@ def stream_box_view(
def stream_box_edit_view(
self, stream_id: int, caption: str = "", title: str = ""
) -> None:
self.in_edit_message_box = True
self.edit_caption = caption

self.stream_write_box = urwid.Text(caption)
self._setup_common_stream_compose(stream_id, caption, title)

self.edit_mode_button = EditModeButton(
Expand Down Expand Up @@ -785,6 +792,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
self.msg_edit_state = None
self.keypress(size, primary_key_for_command("GO_BACK"))
elif is_command_key("GO_BACK", key):

self.in_edit_message_box = False
self.edit_caption = None

self.send_stop_typing_status()
self._set_compose_attributes_to_defaults()
self.view.controller.exit_editor_mode()
Expand Down Expand Up @@ -829,7 +840,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.focus_position == self.FOCUS_CONTAINER_HEADER:
if self.compose_box_status == "open_with_stream":
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 @@ -881,7 +895,10 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
else:
self.focus_position = self.FOCUS_CONTAINER_HEADER
if self.compose_box_status == "open_with_stream":
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 @@ -2030,6 +2047,10 @@ 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 7423415

Please sign in to comment.