compose: Fix "You need to scroll" notifications for large messages.

When you just sent a large message, our logic for "you need to scroll"
notifications did not correctly take into account the height of the
compose box.  This was easily reproduced when sending very long
messages.  The correct solution requires a bit of math to compute what
the visible area will look like after the compose box is closed.

This should be the final fix to #11138.
This commit is contained in:
Tim Abbott
2019-02-05 13:12:28 -08:00
parent 20769f0fe9
commit 309aef4c27
2 changed files with 19 additions and 1 deletions

View File

@@ -78,6 +78,7 @@ function show_box(msg_type, opts) {
}
$("#compose-send-status").removeClass(common.status_classes).hide();
$('#compose').css({visibility: "visible"});
// When changing this, edit the 42px in _maybe_autoscroll
$(".new_message_textarea").css("min-height", "3em");
exports.set_focus(msg_type, opts);

View File

@@ -873,7 +873,24 @@ MessageListView.prototype = {
// still end up being visible, so we do some arithmetic.)
scroll_amount = scroll_limit;
var offset = message_viewport.offset_from_bottom(last_visible);
need_user_to_scroll = offset > scroll_amount;
// For determining whether we need to show the user a "you
// need to scroll down" notification, the obvious check
// would be `offset > scroll_amount`, and that is indeed
// correct with a 1-line message in the compose box.
// However, the compose box is open with the content of
// the message just sent when this code runs, and
// `offset_from_bottom` if an offset from the top of the
// compose box, which is about to be reset to empty. So
// to compute the offset at the time the user might see
// this notification, we need to adjust by the amount that
// the current compose is bigger than the empty, open
// compose box.
var compose_textarea_default_height = 42;
var compose_textarea_current_height = $("#compose-textarea").height();
var expected_change = compose_textarea_current_height - compose_textarea_default_height;
var expected_offset = offset - expected_change;
need_user_to_scroll = expected_offset > scroll_amount;
}
// Ok, we are finally ready to actually scroll.