compose_area: Fix compose_area pasted message bigger than max_length.

Fix a bug where the compose box cut the message without warning the user
the message pasted was longer than the allowed. It was fixed by stopping
cutting the message off and showing an indicator whenever the limit exceeds
and removing the indicator as soon as message gets less than that.

The cut off for showing the indicator is set as 90% of the limit.

Fixes #15909
Co-authored-by: João Maurício <carvalho.joaomauricio@gmail.com>
This commit is contained in:
Priyam Seth
2021-07-07 15:43:19 +05:30
committed by Tim Abbott
parent e976512b3c
commit 62d9f28211
6 changed files with 109 additions and 1 deletions

View File

@@ -464,6 +464,29 @@ function validate_private_message() {
return true;
}
export function check_and_set_overflow_text() {
const text = compose_state.message_content();
const max_length = page_params.max_message_length;
const indicator = $("#compose_limit_indicator");
if (text.length > max_length) {
indicator.addClass("over_limit");
$("#compose-textarea").addClass("over_limit");
indicator.text(text.length + "/" + max_length);
} else if (text.length > 0.9 * max_length) {
indicator.removeClass("over_limit");
$("#compose-textarea").removeClass("over_limit");
indicator.text(text.length + "/" + max_length);
} else {
indicator.text("");
$("#compose-textarea").removeClass("over_limit");
if ($("#compose-send-status").hasClass("alert-error")) {
$("#compose-send-status").stop(true).fadeOut();
}
}
}
export function validate() {
$("#compose-send-button").prop("disabled", true).trigger("blur");
const message_content = compose_state.message_content();
@@ -491,6 +514,12 @@ export function validate() {
return false;
}
if (message_content.length > page_params.max_message_length) {
// We don't display an error message, since the red box already
// communicates clearly what you did wrong.
return false;
}
if (compose_state.get_message_type() === "private") {
return validate_private_message();
}