Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
compose: Avoid preview message area overlap with last message.
Aman Agrawal31dd1d554c5b
diff --git a/frontend_tests/node_tests/compose.js b/frontend_tests/node_tests/compose.jsindex eb7468242fb..8db48179323 100644--- a/frontend_tests/node_tests/compose.js+++ b/frontend_tests/node_tests/compose.js@@ -749,6 +749,11 @@ test_ui("on_events", ({override, override_rewire}) => {})();(function test_markdown_preview_compose_clicked() {+ let reset_compose_textarea_max_height_called = false;+ override(resize, "reset_compose_textarea_max_height", () => {+ reset_compose_textarea_max_height_called = true;+ });+// Tests setupfunction setup_visibilities() {$("#compose-textarea").show();@@ -834,6 +839,7 @@ test_ui("on_events", ({override, override_rewire}) => {assert.equal($("#compose .preview_content").html(), "translated HTML: Nothing to preview");assert_visibilities();+ assert.ok(reset_compose_textarea_max_height_called);let make_indicator_called = false;$("#compose-textarea").val("```foobarfoobar```");diff --git a/static/js/compose.js b/static/js/compose.jsindex 5ad77117b35..31e329dc545 100644--- a/static/js/compose.js+++ b/static/js/compose.js@@ -667,6 +667,7 @@ export function initialize() {$("#compose .preview_content"),content,);+ resize.reset_compose_textarea_max_height();});$("#compose").on("click", ".undo_markdown_preview", (e) => {diff --git a/static/js/resize.js b/static/js/resize.jsindex f4ba1ef3848..0dc3e9f0dc7 100644--- a/static/js/resize.js+++ b/static/js/resize.js@@ -161,10 +161,10 @@ export function watch_manual_resize(element) {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.+ // `compose-textarea` and `preview-textarea`, so that the+ // compose-box's maximum extent does not overlap the last message+ // in the current stream. We also 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) {@@ -172,11 +172,16 @@ export function reset_compose_textarea_max_height(bottom_whitespace_height) {bottom_whitespace_height = h.bottom_whitespace_height;}+ // Take properties of the whichever message area is visible.+ const visible_textarea = $("#compose-textarea:visible, #preview_message_area:visible");const compose_height = Number.parseInt($("#compose").outerHeight(), 10);- const compose_textarea_height = Number.parseInt($("#compose-textarea").outerHeight(), 10);+ const compose_textarea_height = Number.parseInt(visible_textarea.outerHeight(), 10);const compose_non_textarea_height = compose_height - compose_textarea_height;- $("#compose-textarea").css(+ // The `preview_message_area` can have a slightly different height+ // than `compose-textarea` based on operating system. We just+ // ensure that the last message is not overlapped by compose box.+ visible_textarea.css("max-height",// The 10 here leaves space for the selected message border.bottom_whitespace_height - compose_non_textarea_height - 10,