diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.md index 456b13e331..fa4c7c509c 100644 --- a/help/keyboard-shortcuts.md +++ b/help/keyboard-shortcuts.md @@ -25,6 +25,10 @@ in the Zulip app to add more to your repertoire as needed. * **New direct message**: X +* **Paste formatted text**: Ctrl + V + +* **Paste as plain text**: Ctrl + Shift + V + * **Cancel compose and save draft**: Esc or Ctrl + [ — Close the compose box and save the unsent message as a draft. diff --git a/web/src/common.ts b/web/src/common.ts index d154467447..ac9ac166f6 100644 --- a/web/src/common.ts +++ b/web/src/common.ts @@ -80,6 +80,16 @@ export function adjust_mac_kbd_tags(kbd_elem_class: string): void { } $(this).text(key_text); + + // In case of shortcuts, the Mac equivalent of which involves extra keys, + // we use data-mac-following-key attribute to append the extra key to the + // previous key. Currently, this is used to append Opt to Cmd for the Paste + // as plain text shortcut. + const following_key = $(this).attr("data-mac-following-key"); + if (following_key !== undefined) { + const $kbd_elem = $("").text(following_key); + $(this).after(" + ", $kbd_elem); + } }); } diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbs index 1a82965e81..d6a22c72ca 100644 --- a/web/templates/keyboard_shortcuts.hbs +++ b/web/templates/keyboard_shortcuts.hbs @@ -20,6 +20,14 @@ {{t 'New direct message' }} X + + {{t 'Paste formatted text' }} + Ctrl + V + + + {{t 'Paste as plain text' }} + Ctrl + Shift + V + {{t 'Cancel compose and save draft' }} Esc or Ctrl + [ diff --git a/web/tests/common.test.js b/web/tests/common.test.js index 79ea625b91..537391e02c 100644 --- a/web/tests/common.test.js +++ b/web/tests/common.test.js @@ -94,6 +94,7 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => { ["Ctrl+K", "Ctrl+K"], ["[", "["], ["X", "X"], + ["data-mac-following-key", "data-mac-following-key"], ]); const fn_shortcuts = new Set(["Home", "End", "PgUp", "PgDn"]); @@ -114,6 +115,14 @@ run_test("adjust_mac_kbd_tags mac", ({override}) => { assert.equal($elem, inserted_fn_key); }; } + if (old_key === "data-mac-following-key") { + $stub.attr("data-mac-following-key", "⌥"); + $stub.after = (plus, $elem) => { + assert.equal(plus, " + "); + assert.equal($elem.selector, ""); + assert.equal($elem.text(), $stub.attr("data-mac-following-key")); + }; + } test_item.$stub = $stub; test_item.mac_key = mac_key; test_item.adds_arrow_key = fn_shortcuts.has(old_key);