hotkey: Add z shortcut to zoom to message near view.

A new hotkey, lowercase `z` (for `zoom`) has been implemented to allow
the user to go to the near view of the selected message with 1 keypress.
Documentation has been added for this both in the help center, and the
in-app `Keyboard shortcuts` menu.

The effect is identical to clicking on a message's timestamp, which
links to that message's near view.

Fixes: #24227.
This commit is contained in:
N-Shar-ma
2023-02-01 16:28:08 +05:30
committed by Tim Abbott
parent 377b8b22c0
commit 599a32bee9
3 changed files with 33 additions and 0 deletions

View File

@@ -162,6 +162,7 @@ const keypress_mappings = {
118: {name: "show_lightbox", message_view_only: true}, // 'v'
119: {name: "query_users", message_view_only: true}, // 'w'
120: {name: "compose_private_message", message_view_only: true}, // 'x'
122: {name: "zoom_to_message_near", message_view_only: true}, // 'z'
};
export function get_keydown_hotkey(e) {
@@ -991,6 +992,32 @@ export function process_hotkey(e, hotkey) {
stream_popover.build_move_topic_to_stream_popover(msg.stream_id, msg.topic, msg);
return true;
}
case "zoom_to_message_near": {
// The following code is essentially equivalent to
// `window.location = hashutil.by_conversation_and_time_url(msg)`
// but we use `narrow.activate` to pass in the `trigger` parameter
switch (msg.type) {
case "private":
narrow.activate(
[
{operator: "pm-with", operand: msg.reply_to},
{operator: "near", operand: msg.id},
],
{trigger: "hotkey"},
);
return true;
case "stream":
narrow.activate(
[
{operator: "stream", operand: msg.stream},
{operator: "topic", operand: msg.topic},
{operator: "near", operand: msg.id},
],
{trigger: "hotkey"},
);
return true;
}
}
}
return false;

View File

@@ -175,6 +175,10 @@
<td class="definition">{{t 'Narrow to all private messages' }}</td>
<td><span class="hotkey"><kbd>Shift</kbd> + <kbd>P</kbd></span></td>
</tr>
<tr>
<td class="definition">{{t 'Zoom to message in conversation context' }}</td>
<td><span class="hotkey"><kbd>Z</kbd></span></td>
</tr>
<tr>
<td class="definition">{{t 'Narrow to next unread topic' }}</td>
<td><span class="hotkey"><kbd>N</kbd></span></td>