message_edit: Use e.key instead of deprecated e.keyCode.

Tested by making sure Enter and Escape works as expected for editing
topics and messages.
This commit is contained in:
Priyank Patel
2021-05-29 20:08:55 +00:00
committed by Tim Abbott
parent 2cb71ccc7b
commit c292ade96a

View File

@@ -236,9 +236,8 @@ export function end_if_focused_on_message_row_edit() {
} }
function handle_message_row_edit_keydown(e) { function handle_message_row_edit_keydown(e) {
const code = e.keyCode || e.which; switch (e.key) {
switch (code) { case "Enter":
case 13:
if ($(e.target).hasClass("message_edit_content")) { if ($(e.target).hasClass("message_edit_content")) {
// Pressing Enter to save edits is coupled with Enter to send // Pressing Enter to save edits is coupled with Enter to send
if (composebox_typeahead.should_enter_send(e)) { if (composebox_typeahead.should_enter_send(e)) {
@@ -269,7 +268,7 @@ function handle_message_row_edit_keydown(e) {
e.preventDefault(); e.preventDefault();
} }
return; return;
case 27: // Handle escape keys in the message_edit form. case "Escape": // Handle escape keys in the message_edit form.
end_if_focused_on_message_row_edit(); end_if_focused_on_message_row_edit();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
@@ -281,15 +280,14 @@ function handle_message_row_edit_keydown(e) {
function handle_inline_topic_edit_keydown(e) { function handle_inline_topic_edit_keydown(e) {
let row; let row;
const code = e.keyCode || e.which; switch (e.key) {
switch (code) { case "Enter": // Handle Enter key in the recipient bar/inline topic edit form
case 13: // Handle Enter key in the recipient bar/inline topic edit form
row = $(e.target).closest(".recipient_row"); row = $(e.target).closest(".recipient_row");
save_inline_topic_edit(row); save_inline_topic_edit(row);
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();
return; return;
case 27: // handle Esc case "Escape": // handle Esc
end_if_focused_on_inline_topic_edit(); end_if_focused_on_inline_topic_edit();
e.stopPropagation(); e.stopPropagation();
e.preventDefault(); e.preventDefault();