mirror of
https://github.com/zulip/zulip.git
synced 2025-11-20 06:28:23 +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) {
|
function handle_message_row_edit_keydown(e) {
|
||||||
let row;
|
|
||||||
const code = e.keyCode || e.which;
|
const code = e.keyCode || e.which;
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 13:
|
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)) {
|
||||||
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");
|
const message_edit_save_button = row.find(".message_edit_save");
|
||||||
if (message_edit_save_button.attr('disabled') === "disabled") {
|
if (message_edit_save_button.attr('disabled') === "disabled") {
|
||||||
// In cases when the save button is disabled
|
// In cases when the save button is disabled
|
||||||
@@ -171,22 +170,19 @@ function handle_edit_keydown(e) {
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
exports.save_message_row_edit(row);
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
} else {
|
} else {
|
||||||
composebox_typeahead.handle_enter($(e.target), e);
|
composebox_typeahead.handle_enter($(e.target), e);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else if (($(e.target).hasClass("message_edit_topic") ||
|
} else if ($(e.target).hasClass("message_edit_topic") ||
|
||||||
$(e.target).hasClass("message_edit_topic_propagate"))) {
|
$(e.target).hasClass("message_edit_topic_propagate")) {
|
||||||
row = $(e.target).closest(".message_row");
|
const row = $(e.target).closest(".message_row");
|
||||||
exports.save_message_row_edit(row);
|
exports.save_message_row_edit(row);
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
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;
|
return;
|
||||||
case 27: // Handle escape keys in the message_edit form.
|
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) {
|
function timer_text(seconds_left) {
|
||||||
const minutes = Math.floor(seconds_left / 60);
|
const minutes = Math.floor(seconds_left / 60);
|
||||||
const seconds = 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);
|
currently_editing_messages.set(message.id, edit_obj);
|
||||||
current_msg_list.show_edit_message(row, 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)));
|
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) {
|
exports.start_topic_edit = function (recipient_row) {
|
||||||
const form = $(render_topic_edit_form());
|
const form = $(render_topic_edit_form());
|
||||||
current_msg_list.show_edit_topic_on_recipient_row(recipient_row, 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 msg_id = rows.id_for_recipient_row(recipient_row);
|
||||||
const message = current_msg_list.get(msg_id);
|
const message = current_msg_list.get(msg_id);
|
||||||
let topic = message.topic;
|
let topic = message.topic;
|
||||||
|
|||||||
Reference in New Issue
Block a user