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

Support 'Narrow to current compose box recipient'. #1194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/hotkeys.md
Expand Up @@ -80,6 +80,7 @@
|Save current message as a draft|<kbd>meta</kbd> + <kbd>s</kbd>|
|Autocomplete @mentions, #stream_names, :emoji: and topics|<kbd>ctrl</kbd> + <kbd>f</kbd>|
|Cycle through autocomplete suggestions in reverse|<kbd>ctrl</kbd> + <kbd>r</kbd>|
|Narrow to compose box message recipient|<kbd>meta</kbd> + <kbd>.</kbd>|
|Jump to the beginning of line|<kbd>ctrl</kbd> + <kbd>a</kbd>|
|Jump to the end of line|<kbd>ctrl</kbd> + <kbd>e</kbd>|
|Jump backward one word|<kbd>meta</kbd> + <kbd>b</kbd>|
Expand Down
5 changes: 4 additions & 1 deletion tests/helper/test_helper.py
Expand Up @@ -5,6 +5,7 @@
from pytest_mock import MockerFixture

from zulipterminal.api_types import Composition
from zulipterminal.config.keys import primary_key_for_command
from zulipterminal.helper import (
Index,
canonicalize_color,
Expand Down Expand Up @@ -428,8 +429,10 @@ def test_notify_if_message_sent_outside_narrow(
notify_if_message_sent_outside_narrow(req, controller)

if footer_updated:
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")
report_success.assert_called_once_with(
"Message is sent outside of current narrow."
f"Message is sent outside of current narrow. Press [{key}] to narrow to conversation.",
duration=6,
)
else:
report_success.assert_not_called()
Expand Down
5 changes: 5 additions & 0 deletions zulipterminal/config/keys.py
Expand Up @@ -164,6 +164,11 @@ class KeyBinding(TypedDict, total=False):
'help_text': 'Narrow to the topic of the current message',
'key_category': 'msg_actions',
}),
('NARROW_MESSAGE_RECIPIENT', {
'keys': ['meta .'],
'help_text': 'Narrow to compose box message recipient',
'key_category': 'msg_compose',
}),
('TOGGLE_NARROW', {
'keys': ['z'],
'help_text':
Expand Down
8 changes: 7 additions & 1 deletion zulipterminal/helper.py
Expand Up @@ -26,6 +26,7 @@
from typing_extensions import TypedDict

from zulipterminal.api_types import Composition, EmojiType, Message
from zulipterminal.config.keys import primary_key_for_command
from zulipterminal.config.regexes import (
REGEX_COLOR_3_DIGIT,
REGEX_COLOR_6_DIGIT,
Expand Down Expand Up @@ -652,7 +653,12 @@ def check_narrow_and_notify(
and current_narrow != outer_narrow
and current_narrow != inner_narrow
):
controller.report_success("Message is sent outside of current narrow.")
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")

controller.report_success(
f"Message is sent outside of current narrow. Press [{key}] to narrow to conversation.",
duration=6,
)


def notify_if_message_sent_outside_narrow(
Expand Down
21 changes: 21 additions & 0 deletions zulipterminal/ui_tools/boxes.py
Expand Up @@ -773,6 +773,27 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
if self.msg_edit_state is not None:
self.keypress(size, primary_key_for_command("GO_BACK"))
assert self.msg_edit_state is None
elif is_command_key("NARROW_MESSAGE_RECIPIENT", key):
if self.compose_box_status == "open_with_stream":
self.model.controller.narrow_to_topic(
stream_name=self.stream_write_box.edit_text,
topic_name=self.title_write_box.edit_text,
contextual_message_id=None,
)
elif self.compose_box_status == "open_with_private":
self.recipient_emails = [
self.model.user_id_email_dict[user_id]
for user_id in self.recipient_user_ids
]
if self.recipient_user_ids:
self.model.controller.narrow_to_user(
recipient_emails=self.recipient_emails,
contextual_message_id=None,
)
else:
self.view.controller.report_error(
"Cannot narrow to message without specifying recipients."
)
elif is_command_key("GO_BACK", key):
self.send_stop_typing_status()
self._set_compose_attributes_to_defaults()
Expand Down