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

Though the correct mapping for Alt in Mac is Option, we had so far been
mapping it to Command, since for the 2 pre-existing shortcuts that used
Alt, Command was the only key that worked on Mac. However, these are
exceptions.

Now we map Alt to Option, and handle the 2 exceptions separately, using
data attributes on those shortcut elements.

This is a prep commit for introducing a hotkey that uses Alt / Option.
This commit is contained in:
N-Shar-ma 2024-01-25 20:32:04 +05:30 committed by Tim Abbott
parent 536ab78587
commit 972b4de7c4
4 changed files with 12 additions and 16 deletions

View File

@ -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 * **Scroll down**: <kbd>PgDn</kbd>, <kbd>Shift</kbd> + <kbd>J</kbd>, or
<kbd>Spacebar</kbd> <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> <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> <kbd class="arrow-key"></kbd>
## Narrowing ## Narrowing

View File

@ -45,7 +45,7 @@ const keys_map = new Map([
["PgUp", "↑"], ["PgUp", "↑"],
["PgDn", "↓"], ["PgDn", "↓"],
["Ctrl", "⌘"], ["Ctrl", "⌘"],
["Alt", ""], ["Alt", ""],
]); ]);
const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]); 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"); $(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) { if (replace_key !== undefined) {
key_text = replace_key; key_text = replace_key;
} }

View File

@ -107,11 +107,11 @@
</tr> </tr>
<tr> <tr>
<td class="definition">{{t 'Go back through viewing history' }}</td> <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>
<tr> <tr>
<td class="definition">{{t 'Go forward through viewing history' }}</td> <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> </tr>
</table> </table>
</div> </div>

View File

@ -89,7 +89,7 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => {
["PgUp", "↑"], ["PgUp", "↑"],
["PgDn", "↓"], ["PgDn", "↓"],
["Ctrl", "⌘"], ["Ctrl", "⌘"],
["Alt", ""], ["Alt", ""],
["#stream_name", "#stream_name"], ["#stream_name", "#stream_name"],
["Ctrl+K", "Ctrl+K"], ["Ctrl+K", "Ctrl+K"],
["[", "["], ["[", "["],
@ -153,7 +153,6 @@ run_test("adjust_mac_tooltip_keys mac expected", ({override}) => {
[["PgUp"], ["Fn", "↑"]], [["PgUp"], ["Fn", "↑"]],
[["PgDn"], ["Fn", "↓"]], [["PgDn"], ["Fn", "↓"]],
[["Ctrl"], ["⌘"]], [["Ctrl"], ["⌘"]],
[["Alt"], ["⌘"]],
]); ]);
override(navigator, "platform", "MacIntel"); override(navigator, "platform", "MacIntel");
@ -191,14 +190,6 @@ run_test("adjust_mac_tooltip_keys mac random", ({override}) => {
["Shift", "G"], ["Shift", "G"],
], ],
[["Space"], ["Space"]], [["Space"], ["Space"]],
[
["Alt", "←"],
["⌘", "←"],
],
[
["Alt", "→"],
["⌘", "→"],
],
]); ]);
override(navigator, "platform", "MacIntel"); override(navigator, "platform", "MacIntel");