Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

compose-box: Fix compose-box from covering last messages of stream.

Priyansh Garg6cfe10fef276
diff --git a/frontend_tests/node_tests/compose_actions.js b/frontend_tests/node_tests/compose_actions.js
index 52fb518c905..56858ffcc4c 100644
--- a/frontend_tests/node_tests/compose_actions.js
+++ b/frontend_tests/node_tests/compose_actions.js
@@ -45,6 +45,9 @@ mock_esm("../../static/js/message_lists", {
can_mark_messages_read: () => true,
},
});
+mock_esm("../../static/js/resize", {
+ reset_compose_textarea_max_height: noop,
+});
const people = zrequire("people");
diff --git a/static/js/compose_actions.js b/static/js/compose_actions.js
index 68187c7cf90..bcfd0952e79 100644
--- a/static/js/compose_actions.js
+++ b/static/js/compose_actions.js
@@ -23,6 +23,7 @@ import * as people from "./people";
import * as recent_topics_ui from "./recent_topics_ui";
import * as recent_topics_util from "./recent_topics_util";
import * as reload_state from "./reload_state";
+import * as resize from "./resize";
import * as stream_bar from "./stream_bar";
import * as stream_data from "./stream_data";
import * as unread_ops from "./unread_ops";
@@ -265,6 +266,11 @@ export function start(msg_type, opts) {
// Show either stream/topic fields or "You and" field.
show_box(msg_type, opts);
+ // Reset the `max-height` property of `compose-textarea` so that the
+ // compose-box do not cover the last messages of the current stream
+ // while writing a long message.
+ resize.reset_compose_textarea_max_height();
+
complete_starting_tasks(msg_type, opts);
}
diff --git a/static/js/resize.js b/static/js/resize.js
index 83dedd16376..a3c3a4780c7 100644
--- a/static/js/resize.js
+++ b/static/js/resize.js
@@ -159,8 +159,42 @@ export function watch_manual_resize(element) {
return [box_handler, body_handler];
}
+export function reset_compose_textarea_max_height(bottom_whitespace_height) {
+ // If the compose-box is open, we set the `max-height` property of
+ // `compose-textarea` so that the compose-box's maximum extent
+ // does not overlap the last message in the current stream.is the
+ // right size to leave a tiny bit of space after the last message
+ // of the current stream.
+
+ // Compute bottom_whitespace_height if not provided by caller.
+ if (bottom_whitespace_height === undefined) {
+ const h = narrow_window ? left_userlist_get_new_heights() : get_new_heights();
+ bottom_whitespace_height = h.bottom_whitespace_height;
+ }
+
+ const compose_height = Number.parseInt($("#compose").outerHeight(), 10);
+ const compose_textarea_height = Number.parseInt($("#compose-textarea").outerHeight(), 10);
+ const compose_non_textarea_height = compose_height - compose_textarea_height;
+
+ $("#compose-textarea").css(
+ "max-height",
+ // The 10 here leaves space for the selected message border.
+ bottom_whitespace_height - compose_non_textarea_height - 10,
+ );
+}
+
export function resize_bottom_whitespace(h) {
$("#bottom_whitespace").height(h.bottom_whitespace_height);
+
+ // The height of the compose box is tied to that of
+ // bottom_whitespace, so update it if necessary.
+ //
+ // reset_compose_textarea_max_height cannot compute the right
+ // height correctly while compose is hidden. This is OK, because
+ // we also resize compose every time it is opened.
+ if ($(".message_comp").is(":visible")) {
+ reset_compose_textarea_max_height(h.bottom_whitespace_height);
+ }
}
export function resize_stream_filters_container(h) {