Skip to content

Commit

Permalink
core/boxes: Improve handling of pressing Esc during message compose.
Browse files Browse the repository at this point in the history
Fixes zulip#1342.
  • Loading branch information
rsashank committed Nov 11, 2023
1 parent b5819c7 commit 0c7804a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions zulipterminal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,22 @@ def stream_muting_confirmation_popup(
mute_this_stream = partial(self.model.toggle_stream_muted_status, stream_id)
self.loop.widget = PopUpConfirmationView(self, question, mute_this_stream)

def exit_compose_confirmation_popup(self) -> None:
question = urwid.Text(
(
"bold",
"Please confirm that you wish to exit the compose box. "
"(You can save the message as a draft upon returning to compose)",
),
"center",
)
write_box = self.view.write_box
popup_view = PopUpConfirmationView(
self, question, write_box.exit_compose_box, location="center"
)
self.loop.widget = popup_view
self.loop.run()

def copy_to_clipboard(self, text: str, text_category: str) -> None:
try:
pyperclip.copy(text)
Expand Down
8 changes: 8 additions & 0 deletions zulipterminal/ui_tools/boxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,12 @@ def autocomplete_emojis(

return emoji_typeahead, emojis

def exit_compose_box(self) -> None:
self._set_compose_attributes_to_defaults()
self.view.controller.exit_editor_mode()
self.main_view(False)
self.view.middle_column.set_focus("body")

def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.is_in_typeahead_mode and not (
is_command_key("AUTOCOMPLETE", key)
Expand Down Expand Up @@ -801,6 +807,8 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
)
elif is_command_key("GO_BACK", key):
self.send_stop_typing_status()
if len(self.msg_write_box.edit_text) > 10:
self.view.controller.exit_compose_confirmation_popup()
self._set_compose_attributes_to_defaults()
self.view.controller.exit_editor_mode()
self.main_view(False)
Expand Down

0 comments on commit 0c7804a

Please sign in to comment.