Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

hotkey: Correct Mac equivalent of Alt and handle exceptions separately.

N-Shar-ma972b4de7c4c9
diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.md
index 4e55fd30bf5..a8c5c2cd27f 100644
--- a/help/keyboard-shortcuts.md
+++ b/help/keyboard-shortcuts.md
@@ -73,10 +73,10 @@ in the Zulip app to add more to your repertoire as needed.
* **Scroll down**: <kbd>PgDn</kbd>, <kbd>Shift</kbd> + <kbd>J</kbd>, or
<kbd>Spacebar</kbd>
-* **Go back through viewing history**: <kbd>Alt</kbd> +
+* **Go back through viewing history**: <kbd data-mac-key="⌘">Alt</kbd> +
<kbd class="arrow-key">←</kbd>
-* **Go forward through viewing history**: <kbd>Alt</kbd> +
+* **Go forward through viewing history**: <kbd data-mac-key="⌘">Alt</kbd> +
<kbd class="arrow-key">→</kbd>
## Narrowing
diff --git a/web/src/common.ts b/web/src/common.ts
index 0cd303a7070..d1544674470 100644
--- a/web/src/common.ts
+++ b/web/src/common.ts
@@ -45,7 +45,7 @@ const keys_map = new Map([
["PgUp", "↑"],
["PgDn", "↓"],
["Ctrl", "⌘"],
- ["Alt", "⌘"],
+ ["Alt", "⌥"],
]);
const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]);
@@ -69,7 +69,12 @@ export function adjust_mac_kbd_tags(kbd_elem_class: string): void {
$(this).addClass("arrow-key");
}
- const replace_key = keys_map.get(key_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`.
+ 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 e7f1aa81fdb..18496ef3620 100644
--- a/web/templates/keyboard_shortcuts.hbs
+++ b/web/templates/keyboard_shortcuts.hbs
@@ -107,11 +107,11 @@
</tr>
<tr>
<td class="definition">{{t 'Go back through viewing history' }}</td>
- <td><span class="hotkey"><kbd>Alt</kbd> + <kbd class="arrow-key">←</kbd></span></td>
+ <td><span class="hotkey"><kbd data-mac-key="⌘">Alt</kbd> + <kbd class="arrow-key">←</kbd></span></td>
</tr>
<tr>
<td class="definition">{{t 'Go forward through viewing history' }}</td>
- <td><span class="hotkey"><kbd>Alt</kbd> + <kbd class="arrow-key">→</kbd></span></td>
+ <td><span class="hotkey"><kbd data-mac-key="⌘">Alt</kbd> + <kbd class="arrow-key">→</kbd></span></td>
</tr>
</table>
</div>
diff --git a/web/tests/common.test.js b/web/tests/common.test.js
index d9be65885f8..79ea625b915 100644
--- a/web/tests/common.test.js
+++ b/web/tests/common.test.js
@@ -89,7 +89,7 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => {
["PgUp", "↑"],
["PgDn", "↓"],
["Ctrl", "⌘"],
- ["Alt", "⌘"],
+ ["Alt", "⌥"],
["#stream_name", "#stream_name"],
["Ctrl+K", "Ctrl+K"],
["[", "["],
@@ -153,7 +153,6 @@ run_test("adjust_mac_tooltip_keys mac expected", ({override}) => {
[["PgUp"], ["Fn", "↑"]],
[["PgDn"], ["Fn", "↓"]],
[["Ctrl"], ["⌘"]],
- [["Alt"], ["⌘"]],
]);
override(navigator, "platform", "MacIntel");
@@ -191,14 +190,6 @@ run_test("adjust_mac_tooltip_keys mac random", ({override}) => {
["Shift", "G"],
],
[["Space"], ["Space"]],
- [
- ["Alt", "←"],
- ["⌘", "←"],
- ],
- [
- ["Alt", "→"],
- ["⌘", "→"],
- ],
]);
override(navigator, "platform", "MacIntel");