From e29663a2b3c5efe7ace1631fcdb0058c9c338e01 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sat, 18 Feb 2017 22:43:02 -0800 Subject: [PATCH] compose: Fix behavior hitting enter with the preview area open. The new behavior is: (1) If enter-sends is enabled, just send the messsage. (2) If enter-sends is not enabled, return focus to the compose area. Based on great work by khantaalaman in #3673. Fixes #3489. --- static/js/compose.js | 11 +++++++++++ static/js/hotkey.js | 6 ++++++ 2 files changed, 17 insertions(+) diff --git a/static/js/compose.js b/static/js/compose.js index af55ea8cc2..10e46ac608 100644 --- a/static/js/compose.js +++ b/static/js/compose.js @@ -607,6 +607,17 @@ function send_message(request) { } } +exports.enter_with_preview_open = function () { + clear_preview_area(); + if (page_params.enter_sends) { + // If enter_sends is enabled, we just send the message + send_message(); + } else { + // Otherwise, we return to the compose box and focus it + $("#new_message_content").focus(); + } +}; + exports.respond_to_message = function (opts) { var message; var msg_type; diff --git a/static/js/hotkey.js b/static/js/hotkey.js index e19459a242..14f962ea70 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -331,6 +331,12 @@ function process_hotkey(e) { return false; } + // There's special handling for when you're previewing a composition + if ($("#preview_message_area").is(":visible")) { + compose.enter_with_preview_open(); + return true; + } + // Shortcuts that don't require a message switch (event_name) { case 'narrow_private':