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

[WIP] Disable cycling while editing a PM #1280

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
59 changes: 30 additions & 29 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,15 +178,40 @@ def send_stop_typing_status(self) -> None:
self.idle_status_tracking = False
self.sent_start_typing_status = False

def _setup_common_private_compose(self) -> None:
self.set_editor_mode()

self.compose_box_status = "open_with_private"

self.msg_write_box = ReadlineEdit(
multiline=True, max_char=self.model.max_message_length
)
self.msg_write_box.enable_autocomplete(
func=self.generic_autocomplete,
key=primary_key_for_command("AUTOCOMPLETE"),
key_reverse=primary_key_for_command("AUTOCOMPLETE_REVERSE"),
)
self.msg_write_box.set_completer_delims(DELIMS_MESSAGE_COMPOSE)

self.header_write_box = urwid.Columns([self.to_write_box])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.to_write_box is not defined in this method. Rather than needing to assume that when we call this function that it does, we can require that it does, by passing it into the function.

I've not checked, but the equivalent stream function could benefit from a similar refactor.

header_line_box = urwid.Pile(
[
urwid.Divider(COMPOSE_HEADER_TOP),
self.header_write_box,
urwid.Divider(COMPOSE_HEADER_BOTTOM),
]
)
self.contents = [
(header_line_box, self.options()),
(self.msg_write_box, self.options()),
]
self.focus_position = self.FOCUS_CONTAINER_MESSAGE

def private_box_view(
self,
*,
recipient_user_ids: Optional[List[int]] = None,
) -> None:
self.set_editor_mode()

self.compose_box_status = "open_with_private"

if recipient_user_ids:
self._set_regular_and_typing_recipient_user_ids(recipient_user_ids)
self.recipient_emails = [
Expand All @@ -212,31 +237,7 @@ def private_box_view(
key_reverse=primary_key_for_command("AUTOCOMPLETE_REVERSE"),
)
self.to_write_box.set_completer_delims("")

self.msg_write_box = ReadlineEdit(
multiline=True, max_char=self.model.max_message_length
)
self.msg_write_box.enable_autocomplete(
func=self.generic_autocomplete,
key=primary_key_for_command("AUTOCOMPLETE"),
key_reverse=primary_key_for_command("AUTOCOMPLETE_REVERSE"),
)
self.msg_write_box.set_completer_delims(DELIMS_MESSAGE_COMPOSE)

self.header_write_box = urwid.Columns([self.to_write_box])
header_line_box = urwid.Pile(
[
urwid.Divider(COMPOSE_HEADER_TOP),
self.header_write_box,
urwid.Divider(COMPOSE_HEADER_BOTTOM),
]
)
self.contents = [
(header_line_box, self.options()),
(self.msg_write_box, self.options()),
]
self.focus_position = self.FOCUS_CONTAINER_MESSAGE

self._setup_common_private_compose()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To improve readability later, it may be useful to regroup lines in this function, since we're eventually going to have

  • the new user setup function
  • the custom UI header, leading into setting up the common UI part using the header
  • setting up the typing status code

In particular, we have part of the last bullet oddly above this line (send_next_typing_update) and not with the related code. Once the code is simplified, it'd also be good if that was naturally further down, and each group separated by a blank line.

In the edit version you can do any grouping when you introduce it; for this function I'll leave you to decide where to add/leave blank lines and move the line I mentioned, but eg. you delete a blank line in this commit, that could separate where the new function is from the 'timedelta' lines below.

start_period_delta = timedelta(seconds=TYPING_STARTED_WAIT_PERIOD)
stop_period_delta = timedelta(seconds=TYPING_STOPPED_WAIT_PERIOD)

Expand Down