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: Introduce hotkey Alt+P to toggle preview for compose box.

N-Shar-mae4258b56d5c3
diff --git a/help/keyboard-shortcuts.md b/help/keyboard-shortcuts.md
index a8c5c2cd27f..caf03c47cf5 100644
--- a/help/keyboard-shortcuts.md
+++ b/help/keyboard-shortcuts.md
@@ -134,6 +134,8 @@ in the Zulip app to add more to your repertoire as needed.
* **Insert link**: `[Zulip website](https://zulip.org)` or <kbd>Ctrl</kbd> +
<kbd>Shift</kbd> + <kbd>L</kbd>
+* **Toggle preview mode**: <kbd>Alt</kbd> + <kbd>P</kbd>
+
* **Cancel compose and save draft**: <kbd>Esc</kbd> or <kbd>Ctrl</kbd> +
<kbd>[</kbd> — Close the compose box and save the unsent message as a draft.
diff --git a/web/src/hotkey.js b/web/src/hotkey.js
index 0fda9151c79..db8d2a4a803 100644
--- a/web/src/hotkey.js
+++ b/web/src/hotkey.js
@@ -120,6 +120,10 @@ const keydown_cmd_or_ctrl_mappings = {
190: {name: "narrow_to_compose_target", message_view_only: true}, // '.'
};
+const keydown_alt_mappings = {
+ 80: {name: "toggle_compose_preview", message_view_only: true}, // 'P'
+};
+
const keydown_either_mappings = {
// these can be triggered by key or Shift + key
// Note that codes for letters are still case sensitive!
@@ -185,12 +189,16 @@ const keypress_mappings = {
};
export function get_keydown_hotkey(e) {
+ let hotkey;
+
if (e.altKey) {
+ hotkey = keydown_alt_mappings[e.which];
+ if (hotkey) {
+ return hotkey;
+ }
return undefined;
}
- let hotkey;
-
if (e.ctrlKey && !e.shiftKey) {
hotkey = keydown_ctrl_mappings[e.which];
if (hotkey) {
@@ -779,6 +787,15 @@ export function process_hotkey(e, hotkey) {
return true;
}
+ if (event_name === "toggle_compose_preview" && compose_state.composing()) {
+ if ($("#compose .markdown_preview").is(":visible")) {
+ compose.show_preview_area();
+ } else {
+ compose.clear_preview_area();
+ }
+ return true;
+ }
+
if (menu_dropdown_hotkeys.has(event_name) && handle_popover_events(event_name)) {
return true;
}
diff --git a/web/templates/keyboard_shortcuts.hbs b/web/templates/keyboard_shortcuts.hbs
index 18496ef3620..b0744e65f64 100644
--- a/web/templates/keyboard_shortcuts.hbs
+++ b/web/templates/keyboard_shortcuts.hbs
@@ -154,6 +154,10 @@
<td class="definition">{{t 'Insert new line' }}</td>
<td><span class="hotkey"><kbd>Shift</kbd> + <kbd>Enter</kbd></span></td>
</tr>
+ <tr>
+ <td class="definition">{{t 'Toggle preview mode' }}</td>
+ <td><span class="hotkey"><kbd>Alt</kbd> + <kbd>P</kbd></span></td>
+ </tr>
<tr>
<td class="definition">{{t 'Cancel compose and save draft' }}</td>
<td><span class="hotkey"><kbd>Esc</kbd> or <kbd>Ctrl</kbd> + <kbd>[</kbd></span></td>
diff --git a/web/tests/hotkey.test.js b/web/tests/hotkey.test.js
index 71ccfd76c03..694eabaaf51 100644
--- a/web/tests/hotkey.test.js
+++ b/web/tests/hotkey.test.js
@@ -159,12 +159,13 @@ run_test("mappings", () => {
});
}
- function map_down(which, shiftKey, ctrlKey, metaKey) {
+ function map_down(which, shiftKey, ctrlKey, metaKey, altKey) {
return hotkey.get_keydown_hotkey({
which,
shiftKey,
ctrlKey,
metaKey,
+ altKey,
});
}
@@ -194,6 +195,8 @@ run_test("mappings", () => {
assert.equal(map_down(83, false, true).name, "star_message"); // Ctrl + S
assert.equal(map_down(190, false, true).name, "narrow_to_compose_target"); // Ctrl + .
+ assert.equal(map_down(80, false, false, false, true).name, "toggle_compose_preview"); // Alt + P
+
// More negative tests.
assert.equal(map_down(47), undefined);
assert.equal(map_press(27), undefined);