diff --git a/static/js/hotkey.js b/static/js/hotkey.js index bc72cc1497..a3f135f108 100644 --- a/static/js/hotkey.js +++ b/static/js/hotkey.js @@ -178,8 +178,6 @@ exports.in_content_editable_widget = function (e) { // Returns true if we handled it, false if the browser should. exports.process_escape_key = function (e) { - let row; - if (exports.in_content_editable_widget(e)) { return false; } @@ -204,32 +202,7 @@ exports.process_escape_key = function (e) { return true; } - if (message_edit.is_editing(current_msg_list.selected_id())) { - // Using this definition of "row" instead of "current_msg_list.selected_row()" - // because it returns a more complete object. - // Necessary for refocusing on message list in Firefox. - const message_edit_inputs = $(".message_edit_content, .message_edit_topic"); - row = message_edit_inputs.filter(":focus").closest(".message_row"); - row.find('.message_edit_content').blur(); - message_edit.end(row); - return true; - } - if (exports.processing_text()) { - if ($(".message_edit_content").filter(":focus").length > 0) { - row = $(".message_edit_content").filter(":focus").closest(".message_row"); - row.find('.message_edit_content').blur(); - message_edit.end(row); - return true; - } - - if ($(".message_edit_topic").filter(":focus").length > 0) { - row = $(".message_edit_topic").filter(":focus").closest(".message_row"); - row.find('.message_edit_topic').blur(); - message_edit.end(row); - return true; - } - if (activity.searching()) { activity.escape_search(); return true; diff --git a/static/js/message_edit.js b/static/js/message_edit.js index 42b7896dd0..7a6d5d34b4 100644 --- a/static/js/message_edit.js +++ b/static/js/message_edit.js @@ -143,10 +143,28 @@ exports.show_topic_edit_spinner = function (row) { $(".topic_edit_cancel").hide(); }; +exports.end_if_focused = function () { + const focused_elem = $(".message_edit").find(':focus'); + + if (focused_elem.length === 1) { + focused_elem.blur(); + const row = focused_elem.closest('.message_row'); + exports.end(row); + } +}; + function handle_edit_keydown(from_topic_edited_only, e) { let row; const code = e.keyCode || e.which; + // Handle escape keys in the message_edit form. + if (code === 27) { + exports.end_if_focused(); + e.stopPropagation(); + e.preventDefault(); + return; + } + if ($(e.target).hasClass("message_edit_content") && code === 13) { // Pressing enter to save edits is coupled with enter to send if (composebox_typeahead.should_enter_send(e)) {