From bc0f9c487695f4111289ae2005e6bc71f7110ff8 Mon Sep 17 00:00:00 2001 From: Lauryn Menard Date: Fri, 1 Nov 2024 12:42:55 +0100 Subject: [PATCH] keyboard-shortcuts: Display "Ctrl" for Vim "Esc" keybinding behavior. For all users, we want to display "Ctrl" for the "Ctrl" "[" keyboard shortcuts that match the "Esc" Vim keybinding behavior. We use the "data-mac-key" attribute to override the default mapping of "Ctrl" to "Cmd" for Mac users in the documentation of these keyboard shortcuts. Fixes #20107. --- help/configure-home-view.md | 11 ++++++----- help/keyboard-shortcuts.md | 15 ++++++++------- web/src/common.ts | 12 ++++++++---- web/templates/keyboard_shortcuts.hbs | 6 +++--- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/help/configure-home-view.md b/help/configure-home-view.md index a0b9cc35b8..6f958508de 100644 --- a/help/configure-home-view.md +++ b/help/configure-home-view.md @@ -13,8 +13,8 @@ on how to use these views. You can configure which view is set as your home view, and whether the Esc key navigates to the home view. Also, you can -always reach the home view by using the Ctrl + [ -shortcut. +always reach the home view by using the +Ctrl + [ shortcut. ## Change home view @@ -44,7 +44,8 @@ organization settings: 1. To see your changes in action, open a new Zulip tab, or use a keyboard shortcut twice to exit the settings and navigate to your home view - (Ctrl + [ or Esc if enabled). + (Ctrl + [ or Esc + if enabled). !!! tip "" @@ -62,8 +63,8 @@ designed to enhance the user experience in the app. By default, the Esc key shortcut will ultimately navigate to your home view. You can disable this key binding if you would prefer. This will not disable other Esc key shortcuts used in Zulip, -and will not affect the behavior of the Ctrl + [ -shortcut. +and will not affect the behavior of the +Ctrl + [ shortcut. ### Toggle whether Esc navigates to the home view diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.md index 0fc927325b..c6c025e7db 100644 --- a/help/keyboard-shortcuts.md +++ b/help/keyboard-shortcuts.md @@ -32,9 +32,9 @@ in the Zulip app to add more to your repertoire as needed. Ctrl + V, and press Ctrl + Z to remove formatting. -* **Cancel compose and save draft**: Esc or Ctrl + - [ — Close the compose box and save the unsent message as a - draft. +* **Cancel compose and save draft**: Esc or + Ctrl + [ — Close the compose box + and save the unsent message as a draft. * **View drafts**: D — Use the arrow keys and Enter to restore a draft. Press D again to close. @@ -54,8 +54,8 @@ in the Zulip app to add more to your repertoire as needed. * **Toggle keyboard shortcuts view**: ? -* **Go to your home view**: Ctrl + [ (or - Esc, [if enabled][disable-escape]) +* **Go to your home view**: Ctrl + [ + (or Esc, [if enabled][disable-escape]) until you are in your [home view](/help/configure-home-view). [disable-escape]: /help/configure-home-view#configure-whether-esc-navigates-to-the-home-view @@ -158,8 +158,9 @@ in the Zulip app to add more to your repertoire as needed. * **Toggle preview mode**: Alt + P -* **Cancel compose and save draft**: Esc or Ctrl + - [ — Close the compose box and save the unsent message as a draft. +* **Cancel compose and save draft**: Esc or + Ctrl + [ — Close the compose box + and save the unsent message as a draft. ## Message actions diff --git a/web/src/common.ts b/web/src/common.ts index 9e80d2b70a..d9b5018a76 100644 --- a/web/src/common.ts +++ b/web/src/common.ts @@ -34,10 +34,14 @@ export function adjust_mac_kbd_tags(kbd_elem_class: string): void { let key_text = $(this).text(); // We use data-mac-key attribute to override the default key in case - // of exceptions. Currently, there are 2 shortcuts (for navigating back - // and forth in browser history) which need `Cmd` instead of the expected - // mapping (`Opt`) for the `Alt` key, so we use this attribute to override - // `Opt` with `Cmd`. + // of exceptions: + // - There are 2 shortcuts (for navigating back and forth in browser + // history) which need "⌘" instead of the expected mapping ("Opt") + // for the "Alt" key, so we use this attribute to override "Opt" + // with "⌘". + // - The "Ctrl" + "[" shortcuts (which match the Vim keybinding behavior + // of mapping to "Esc") need to display "Ctrl" for all users, so we + // use this attribute to override "⌘" with "Ctrl". const replace_key = $(this).attr("data-mac-key") ?? keys_map.get(key_text); if (replace_key !== undefined) { key_text = replace_key; diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbs index 9a3b75cc9b..ddd9a7a872 100644 --- a/web/templates/keyboard_shortcuts.hbs +++ b/web/templates/keyboard_shortcuts.hbs @@ -30,7 +30,7 @@ {{t 'Cancel compose and save draft' }} - Esc or Ctrl + [ + Esc or Ctrl + [ {{t 'View drafts' }} @@ -66,7 +66,7 @@ {{t 'Go to your home view' }} - Ctrl + [ or Esc + Ctrl + [ or Esc @@ -238,7 +238,7 @@ {{t 'Cancel compose and save draft' }} - Esc or Ctrl + [ + Esc or Ctrl + [