mirror of https://github.com/zulip/zulip.git
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:
parent
b0c90c0ba2
commit
dc938768ca
|
@ -342,37 +342,35 @@ export function update_inline_topic_edit_ui() {
|
||||||
message_live_update.rerender_messages_view();
|
message_live_update.rerender_messages_view();
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_message_row_edit_keydown(e) {
|
function handle_message_edit_enter(e, $message_edit_content) {
|
||||||
if (keydown_util.is_enter_event(e)) {
|
// Pressing Enter to save edits is coupled with Enter to send
|
||||||
if ($(e.target).hasClass("message_edit_content")) {
|
if (composebox_typeahead.should_enter_send(e)) {
|
||||||
// Pressing Enter to save edits is coupled with Enter to send
|
const $row = $(".message_edit_content:focus").closest(".message_row");
|
||||||
if (composebox_typeahead.should_enter_send(e)) {
|
const $message_edit_save_button = $row.find(".message_edit_save");
|
||||||
const $row = $(".message_edit_content:focus").closest(".message_row");
|
if ($message_edit_save_button.prop("disabled")) {
|
||||||
const $message_edit_save_button = $row.find(".message_edit_save");
|
// In cases when the save button is disabled
|
||||||
if ($message_edit_save_button.prop("disabled")) {
|
// we need to disable save on pressing Enter
|
||||||
// In cases when the save button is disabled
|
// Prevent default to avoid new-line on pressing
|
||||||
// we need to disable save on pressing Enter
|
// Enter inside the textarea in this case
|
||||||
// Prevent default to avoid new-line on pressing
|
e.preventDefault();
|
||||||
// Enter inside the textarea in this case
|
return;
|
||||||
e.preventDefault();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
save_message_row_edit($row);
|
|
||||||
e.stopPropagation();
|
|
||||||
e.preventDefault();
|
|
||||||
} else {
|
|
||||||
composebox_typeahead.handle_enter($(e.target), e);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (e.key === "Escape") {
|
save_message_row_edit($row);
|
||||||
end_if_focused_on_message_row_edit();
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
} else {
|
||||||
|
composebox_typeahead.handle_enter($message_edit_content, e);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handle_inline_topic_edit_keydown(e) {
|
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, $recipient_row) {
|
||||||
if (keydown_util.is_enter_event(e)) {
|
if (keydown_util.is_enter_event(e)) {
|
||||||
// Handle Enter key in the recipient bar/inline topic edit form
|
// Handle Enter key in the recipient bar/inline topic edit form
|
||||||
if ($(".typeahead:visible").length > 0) {
|
if ($(".typeahead:visible").length > 0) {
|
||||||
|
@ -380,8 +378,7 @@ function handle_inline_topic_edit_keydown(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const $row = $(e.target).closest(".recipient_row");
|
try_save_inline_topic_edit($recipient_row);
|
||||||
try_save_inline_topic_edit($row);
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
} else if (e.key === "Escape") {
|
} else if (e.key === "Escape") {
|
||||||
|
@ -471,7 +468,17 @@ function edit_message($row, raw_content) {
|
||||||
currently_editing_messages.set(message.id, $message_edit_content);
|
currently_editing_messages.set(message.id, $message_edit_content);
|
||||||
message_lists.current.show_edit_message($row, $form);
|
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
|
$form
|
||||||
.find(".message-edit-feature-group .video_link")
|
.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);
|
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();
|
$(".topic_edit_spinner").hide();
|
||||||
const msg_id = rows.id_for_recipient_row($recipient_row);
|
const msg_id = rows.id_for_recipient_row($recipient_row);
|
||||||
const message = message_lists.current.get(msg_id);
|
const message = message_lists.current.get(msg_id);
|
||||||
|
|
Loading…
Reference in New Issue