Skip to content

Commit c7270f7

Browse files
committed
helper/boxes/keys/hotkeys: Narrow to current compose box recipient.
Fixes #1182
1 parent 212e4ac commit c7270f7

File tree

5 files changed

+37
-2
lines changed

5 files changed

+37
-2
lines changed

docs/hotkeys.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@
8080
|Save current message as a draft|<kbd>meta</kbd> + <kbd>s</kbd>|
8181
|Autocomplete @mentions, #stream_names, :emoji: and topics|<kbd>ctrl</kbd> + <kbd>f</kbd>|
8282
|Cycle through autocomplete suggestions in reverse|<kbd>ctrl</kbd> + <kbd>r</kbd>|
83+
|Narrow to compose box message recipient|<kbd>meta</kbd> + <kbd>.</kbd>|
8384
|Jump to the beginning of line|<kbd>ctrl</kbd> + <kbd>a</kbd>|
8485
|Jump to the end of line|<kbd>ctrl</kbd> + <kbd>e</kbd>|
8586
|Jump backward one word|<kbd>meta</kbd> + <kbd>b</kbd>|

tests/helper/test_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from pytest_mock import MockerFixture
66

77
from zulipterminal.api_types import Composition
8+
from zulipterminal.config.keys import primary_key_for_command
89
from zulipterminal.helper import (
910
Index,
1011
canonicalize_color,
@@ -428,8 +429,9 @@ def test_notify_if_message_sent_outside_narrow(
428429
notify_if_message_sent_outside_narrow(req, controller)
429430

430431
if footer_updated:
432+
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")
431433
report_success.assert_called_once_with(
432-
"Message is sent outside of current narrow."
434+
f"Message is sent outside of current narrow. Press [{key}] to narrow to conversation.", duration=6
433435
)
434436
else:
435437
report_success.assert_not_called()

zulipterminal/config/keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,11 @@ class KeyBinding(TypedDict, total=False):
164164
'help_text': 'Narrow to the topic of the current message',
165165
'key_category': 'msg_actions',
166166
}),
167+
('NARROW_MESSAGE_RECIPIENT', {
168+
'keys': ['meta .'],
169+
'help_text': 'Narrow to compose box message recipient',
170+
'key_category': 'msg_compose',
171+
}),
167172
('TOGGLE_NARROW', {
168173
'keys': ['z'],
169174
'help_text':

zulipterminal/helper.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing_extensions import TypedDict
2727

2828
from zulipterminal.api_types import Composition, EmojiType, Message
29+
from zulipterminal.config.keys import primary_key_for_command
2930
from zulipterminal.config.regexes import (
3031
REGEX_COLOR_3_DIGIT,
3132
REGEX_COLOR_6_DIGIT,
@@ -652,7 +653,12 @@ def check_narrow_and_notify(
652653
and current_narrow != outer_narrow
653654
and current_narrow != inner_narrow
654655
):
655-
controller.report_success("Message is sent outside of current narrow.")
656+
key = primary_key_for_command("NARROW_MESSAGE_RECIPIENT")
657+
658+
controller.report_success(
659+
f"Message is sent outside of current narrow. Press [{key}] to narrow to conversation.",
660+
duration=6,
661+
)
656662

657663

658664
def notify_if_message_sent_outside_narrow(

zulipterminal/ui_tools/boxes.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,27 @@ def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
773773
if self.msg_edit_state is not None:
774774
self.keypress(size, primary_key_for_command("GO_BACK"))
775775
assert self.msg_edit_state is None
776+
elif is_command_key("NARROW_MESSAGE_RECIPIENT", key):
777+
if self.compose_box_status == "open_with_stream":
778+
self.model.controller.narrow_to_topic(
779+
stream_name=self.stream_write_box.edit_text,
780+
topic_name=self.title_write_box.edit_text,
781+
contextual_message_id=None,
782+
)
783+
else:
784+
self.recipient_emails = [
785+
self.model.user_id_email_dict[user_id]
786+
for user_id in self.recipient_user_ids
787+
]
788+
if self.recipient_user_ids:
789+
self.model.controller.narrow_to_user(
790+
recipient_emails=self.recipient_emails,
791+
contextual_message_id=None,
792+
)
793+
else:
794+
self.view.controller.report_error(
795+
"Cannot narrow to message without specifying recipients."
796+
)
776797
elif is_command_key("GO_BACK", key):
777798
self.send_stop_typing_status()
778799
self._set_compose_attributes_to_defaults()

0 commit comments

Comments
 (0)