Skip to content

Commit 95e92fb

Browse files
committed
buttons/keys/views: Introduce hotkey "c" for copying code snippets.
Introduces "c" hotkey to copy code snippets from the Message Information popup. Updates hotkeys linting to exclude "c". Tests updated. Fixes #1123.
1 parent 97638ee commit 95e92fb

File tree

6 files changed

+23
-5
lines changed

6 files changed

+23
-5
lines changed

docs/hotkeys.md

+1
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
|View current message in browser (from message information)|<kbd>v</kbd>|
6565
|Show/hide full rendered message (from message information)|<kbd>f</kbd>|
6666
|Show/hide full raw message (from message information)|<kbd>r</kbd>|
67+
|Copy code snippet to clipboard (from message information)|<kbd>c</kbd>|
6768

6869
## Stream list actions
6970
|Command|Key Combination|

tests/ui_tools/test_popups.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -1117,13 +1117,14 @@ def test_keypress_view_in_browser(
11171117
assert self.controller.open_in_browser.called
11181118

11191119
def test_height_noreactions(self) -> None:
1120-
expected_height = 8
1121-
# 6 = 1 (date & time) +1 (sender's name) +1 (sender's email)
1120+
expected_height = 9
1121+
# 3 = 1 (date & time) +1 (sender's name) +1 (sender's email)
11221122
# +1 (display group header)
11231123
# +1 (whitespace column)
11241124
# +1 (view message in browser)
11251125
# +1 (full rendered message)
11261126
# +1 (full raw message)
1127+
# +1 (copy code snippet)
11271128
assert self.msg_info_view.height == expected_height
11281129

11291130
# FIXME This is the same parametrize as MessageBox:test_reactions_view
@@ -1192,9 +1193,9 @@ def test_height_reactions(
11921193
list(),
11931194
list(),
11941195
)
1195-
# 12 = 7 labels + 2 blank lines + 1 'Reactions' (category)
1196+
# 11 = 8 labels + 2 blank lines + 1 'Reactions' (category)
11961197
# + 4 reactions (excluding 'Message Links').
1197-
expected_height = 14
1198+
expected_height = 15
11981199
assert self.msg_info_view.height == expected_height
11991200

12001201
@pytest.mark.parametrize(

tools/lint-hotkeys

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ SCRIPT_NAME = PurePath(__file__).name
1919
HELP_TEXT_STYLE = re.compile(r"^[a-zA-Z /()',&@#:_-]*$")
2020

2121
# Exclude keys from duplicate keys checking
22-
KEYS_TO_EXCLUDE = ["q", "e", "m", "r"]
22+
KEYS_TO_EXCLUDE = ["q", "e", "m", "r", "c"]
2323

2424

2525
def main(fix: bool) -> None:

zulipterminal/config/keys.py

+7
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,13 @@ class KeyBinding(TypedDict):
405405
'help_text': 'Show/hide full raw message (from message information)',
406406
'key_category': 'msg_actions',
407407
},
408+
'COPY_CODE_SNIPPET': {
409+
'keys': ['c'],
410+
'help_text':
411+
'Copy code snippet to clipboard (from message information)',
412+
'excluded_from_random_tips': True,
413+
'key_category': 'msg_actions'
414+
},
408415
}
409416
# fmt: on
410417

zulipterminal/ui_tools/buttons.py

+5
Original file line numberDiff line numberDiff line change
@@ -742,6 +742,11 @@ def extract_display_code(self, snippet_list: List[Tuple[str, str]]) -> None:
742742
)
743743
self.display_code = [("pygments:w", self.caption)] + self.display_code
744744

745+
def keypress(self, size: urwid_Size, key: str) -> Optional[str]:
746+
if is_command_key("COPY_CODE_SNIPPET", key):
747+
urwid.emit_signal(self, "click")
748+
return super().keypress(size, key)
749+
745750

746751
class EditModeButton(urwid.Button):
747752
def __init__(self, *, controller: Any, width: int) -> None:

zulipterminal/ui_tools/views.py

+4
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,9 @@ def __init__(
15821582
full_raw_message_keys = "[{}]".format(
15831583
", ".join(map(str, display_keys_for_command("FULL_RAW_MESSAGE")))
15841584
)
1585+
copy_code_keys = "[{}]".format(
1586+
", ".join(map(str, display_keys_for_command("COPY_CODE_SNIPPET")))
1587+
)
15851588
msg_info = [
15861589
(
15871590
"",
@@ -1600,6 +1603,7 @@ def __init__(
16001603
("Open in web browser", view_in_browser_keys),
16011604
("Full rendered message", full_rendered_message_keys),
16021605
("Full raw message", full_raw_message_keys),
1606+
("Copy code snippet", copy_code_keys),
16031607
],
16041608
)
16051609
msg_info.append(viewing_actions)

0 commit comments

Comments
 (0)