compose: Replace $("textarea#compose-textarea") with $textarea.

Replaces the $("textarea#compose-textarea") selector with $textarea in
the `check_overflow_text` and `validate_message_length` functions. This
change allows $textarea to be modified in future commits to also support
the edit-message UI.
This commit is contained in:
opmkumar
2024-11-22 22:34:11 +05:30
committed by Tim Abbott
parent aac07e913b
commit 7c53e8c90b

View File

@@ -721,6 +721,7 @@ export function check_overflow_text(): number {
// This function is called when typing every character in the // This function is called when typing every character in the
// compose box, so it's important that it not doing anything // compose box, so it's important that it not doing anything
// expensive. // expensive.
const $textarea = $("textarea#compose-textarea");
const text = compose_state.message_content(); const text = compose_state.message_content();
const max_length = realm.max_message_length; const max_length = realm.max_message_length;
const remaining_characters = max_length - text.length; const remaining_characters = max_length - text.length;
@@ -728,7 +729,7 @@ export function check_overflow_text(): number {
if (text.length > max_length) { if (text.length > max_length) {
$indicator.addClass("over_limit"); $indicator.addClass("over_limit");
$("textarea#compose-textarea").addClass("over_limit"); $textarea.addClass("over_limit");
$indicator.html( $indicator.html(
render_compose_limit_indicator({ render_compose_limit_indicator({
remaining_characters, remaining_characters,
@@ -737,7 +738,7 @@ export function check_overflow_text(): number {
set_message_too_long_for_compose(true); set_message_too_long_for_compose(true);
} else if (remaining_characters <= 900) { } else if (remaining_characters <= 900) {
$indicator.removeClass("over_limit"); $indicator.removeClass("over_limit");
$("textarea#compose-textarea").removeClass("over_limit"); $textarea.removeClass("over_limit");
$indicator.html( $indicator.html(
render_compose_limit_indicator({ render_compose_limit_indicator({
remaining_characters, remaining_characters,
@@ -746,7 +747,7 @@ export function check_overflow_text(): number {
set_message_too_long_for_compose(false); set_message_too_long_for_compose(false);
} else { } else {
$indicator.text(""); $indicator.text("");
$("textarea#compose-textarea").removeClass("over_limit"); $textarea.removeClass("over_limit");
set_message_too_long_for_compose(false); set_message_too_long_for_compose(false);
} }
@@ -755,9 +756,10 @@ export function check_overflow_text(): number {
} }
export function validate_message_length(): boolean { export function validate_message_length(): boolean {
const $textarea = $("textarea#compose-textarea");
if (compose_state.message_content().length > realm.max_message_length) { if (compose_state.message_content().length > realm.max_message_length) {
$("textarea#compose-textarea").addClass("flash"); $textarea.addClass("flash");
setTimeout(() => $("textarea#compose-textarea").removeClass("flash"), 1500); setTimeout(() => $textarea.removeClass("flash"), 1500);
return false; return false;
} }
return true; return true;