message_edit: Avoid use of e.target.

This commit changes some event handlers to pass in relevant
JQuery objects instead of using `e.target`. This will be
necessary for converting message_edit to typescript.
This commit is contained in:
evykassirer 2024-08-15 09:37:25 -07:00 committed by Tim Abbott
parent b0c90c0ba2
commit dc938768ca
1 changed files with 38 additions and 29 deletions

View File

@ -342,9 +342,7 @@ export function update_inline_topic_edit_ui() {
message_live_update.rerender_messages_view();
}
function handle_message_row_edit_keydown(e) {
if (keydown_util.is_enter_event(e)) {
if ($(e.target).hasClass("message_edit_content")) {
function handle_message_edit_enter(e, $message_edit_content) {
// Pressing Enter to save edits is coupled with Enter to send
if (composebox_typeahead.should_enter_send(e)) {
const $row = $(".message_edit_content:focus").closest(".message_row");
@ -361,18 +359,18 @@ function handle_message_row_edit_keydown(e) {
e.stopPropagation();
e.preventDefault();
} else {
composebox_typeahead.handle_enter($(e.target), e);
composebox_typeahead.handle_enter($message_edit_content, e);
return;
}
}
} else if (e.key === "Escape") {
function handle_message_row_edit_escape(e) {
end_if_focused_on_message_row_edit();
e.stopPropagation();
e.preventDefault();
}
}
function handle_inline_topic_edit_keydown(e) {
function handle_inline_topic_edit_keydown(e, $recipient_row) {
if (keydown_util.is_enter_event(e)) {
// Handle Enter key in the recipient bar/inline topic edit form
if ($(".typeahead:visible").length > 0) {
@ -380,8 +378,7 @@ function handle_inline_topic_edit_keydown(e) {
e.preventDefault();
return;
}
const $row = $(e.target).closest(".recipient_row");
try_save_inline_topic_edit($row);
try_save_inline_topic_edit($recipient_row);
e.stopPropagation();
e.preventDefault();
} else if (e.key === "Escape") {
@ -471,7 +468,17 @@ function edit_message($row, raw_content) {
currently_editing_messages.set(message.id, $message_edit_content);
message_lists.current.show_edit_message($row, $form);
$form.on("keydown", handle_message_row_edit_keydown);
$message_edit_content.on("keydown", (e) => {
if (keydown_util.is_enter_event(e)) {
handle_message_edit_enter(e, $message_edit_content);
}
});
$form.on("keydown", (e) => {
if (e.key === "Escape") {
handle_message_row_edit_escape(e);
}
});
$form
.find(".message-edit-feature-group .video_link")
@ -753,7 +760,9 @@ export function start_inline_topic_edit($recipient_row) {
}),
);
message_lists.current.show_edit_topic_on_recipient_row($recipient_row, $form);
$form.on("keydown", handle_inline_topic_edit_keydown);
$form.on("keydown", (e) => {
handle_inline_topic_edit_keydown(e, $recipient_row);
});
$(".topic_edit_spinner").hide();
const msg_id = rows.id_for_recipient_row($recipient_row);
const message = message_lists.current.get(msg_id);