From 599a32bee91adff2bfa8cc475f111c6b6d2dbe8d Mon Sep 17 00:00:00 2001 From: N-Shar-ma Date: Wed, 1 Feb 2023 16:28:08 +0530 Subject: [PATCH] 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. --- help/keyboard-shortcuts.md | 2 ++ web/src/hotkey.js | 27 +++++++++++++++++++++++++++ web/templates/keyboard_shortcuts.hbs | 4 ++++ 3 files changed, 33 insertions(+) diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.md index d3b237ff71..8fc8fd5cd6 100644 --- a/help/keyboard-shortcuts.md +++ b/help/keyboard-shortcuts.md @@ -89,6 +89,8 @@ in the Zulip app to add more to your repertoire as needed. * **Narrow to all private messages**: Shift + P +* **Zoom to message in conversation context**: Z — This view does not mark messages as read. + * **Cycle between stream narrows**: Shift + A (previous) and Shift + D (next) diff --git a/web/src/hotkey.js b/web/src/hotkey.js index beda6929e5..40eda88464 100644 --- a/web/src/hotkey.js +++ b/web/src/hotkey.js @@ -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; diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbs index b8d3bd8dfe..3b907d6b4a 100644 --- a/web/templates/keyboard_shortcuts.hbs +++ b/web/templates/keyboard_shortcuts.hbs @@ -175,6 +175,10 @@ {{t 'Narrow to all private messages' }} Shift + P + + {{t 'Zoom to message in conversation context' }} + Z + {{t 'Narrow to next unread topic' }} N