mirror of
https://github.com/zulip/zulip.git
synced 2025-11-19 05:58:25 +00:00
message_edit: Refactor handle_edit_keydown to separate inline topic edits.
This commit cleans up the dirty if/else structure of handle_edit_keydown by switching to switch case statements, and also separates the handler for inline_topic_edits and that for message row edits.
This commit is contained in:
@@ -153,15 +153,14 @@ exports.end_if_focused = function () {
|
||||
}
|
||||
};
|
||||
|
||||
function handle_edit_keydown(e) {
|
||||
let row;
|
||||
function handle_message_row_edit_keydown(e) {
|
||||
const code = e.keyCode || e.which;
|
||||
switch (code) {
|
||||
case 13:
|
||||
if ($(e.target).hasClass("message_edit_content")) {
|
||||
// Pressing enter to save edits is coupled with enter to send
|
||||
if (composebox_typeahead.should_enter_send(e)) {
|
||||
row = $(".message_edit_content").filter(":focus").closest(".message_row");
|
||||
const row = $(".message_edit_content").filter(":focus").closest(".message_row");
|
||||
const message_edit_save_button = row.find(".message_edit_save");
|
||||
if (message_edit_save_button.attr('disabled') === "disabled") {
|
||||
// In cases when the save button is disabled
|
||||
@@ -171,22 +170,19 @@ function handle_edit_keydown(e) {
|
||||
e.preventDefault();
|
||||
return;
|
||||
}
|
||||
exports.save_message_row_edit(row);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
} else {
|
||||
composebox_typeahead.handle_enter($(e.target), e);
|
||||
return;
|
||||
}
|
||||
} else if (($(e.target).hasClass("message_edit_topic") ||
|
||||
$(e.target).hasClass("message_edit_topic_propagate"))) {
|
||||
row = $(e.target).closest(".message_row");
|
||||
} else if ($(e.target).hasClass("message_edit_topic") ||
|
||||
$(e.target).hasClass("message_edit_topic_propagate")) {
|
||||
const row = $(e.target).closest(".message_row");
|
||||
exports.save_message_row_edit(row);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
} else if (e.target.id === "inline_topic_edit") {
|
||||
row = $(e.target).closest(".recipient_row");
|
||||
exports.show_topic_edit_spinner(row);
|
||||
exports.save_inline_topic_edit(row);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
}
|
||||
return;
|
||||
case 27: // Handle escape keys in the message_edit form.
|
||||
@@ -199,6 +195,22 @@ function handle_edit_keydown(e) {
|
||||
}
|
||||
}
|
||||
|
||||
function handle_inline_topic_edit_keydown(e) {
|
||||
let row;
|
||||
const code = e.keyCode || e.which;
|
||||
switch (code) {
|
||||
case 13: // Handle enter key in the recipient bar/inline topic edit form
|
||||
row = $(e.target).closest(".recipient_row");
|
||||
exports.show_topic_edit_spinner(row);
|
||||
exports.save_inline_topic_edit(row);
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
function timer_text(seconds_left) {
|
||||
const minutes = Math.floor(seconds_left / 60);
|
||||
const seconds = seconds_left % 60;
|
||||
@@ -256,7 +268,7 @@ function edit_message(row, raw_content) {
|
||||
currently_editing_messages.set(message.id, edit_obj);
|
||||
current_msg_list.show_edit_message(row, edit_obj);
|
||||
|
||||
form.keydown(_.partial(handle_edit_keydown, false));
|
||||
form.keydown(handle_message_row_edit_keydown);
|
||||
|
||||
upload.feature_check($('#attach_files_' + rows.id(row)));
|
||||
|
||||
@@ -433,7 +445,7 @@ exports.start = function (row, edit_box_open_callback) {
|
||||
exports.start_topic_edit = function (recipient_row) {
|
||||
const form = $(render_topic_edit_form());
|
||||
current_msg_list.show_edit_topic_on_recipient_row(recipient_row, form);
|
||||
form.keydown(_.partial(handle_edit_keydown, true));
|
||||
form.keydown(handle_inline_topic_edit_keydown);
|
||||
const msg_id = rows.id_for_recipient_row(recipient_row);
|
||||
const message = current_msg_list.get(msg_id);
|
||||
let topic = message.topic;
|
||||
|
||||
Reference in New Issue
Block a user