mirror of
https://github.com/zulip/zulip.git
synced 2025-11-06 15:03:34 +00:00
Slow down pointer adjustments at the bottom of the messages.
The main point of this fix is to move some more scroll-related code into viewport.js, but it also fixes a bug where the size of #main_div was not accurately representing the full height of the message list. Making the calculation more accurate narrows the window where we do pointer adjustements on mousewheel moves. (imported from commit 5d821f459284c4dbd5ff8056001e54caf4355f1d)
This commit is contained in:
@@ -151,7 +151,7 @@ function process_hotkey(e) {
|
|||||||
|
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 33: // Page Up
|
case 33: // Page Up
|
||||||
if (at_top_of_viewport() && !current_msg_list.empty()) {
|
if (viewport.at_top() && !current_msg_list.empty()) {
|
||||||
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
|
current_msg_list.select_id(current_msg_list.first().id, {then_scroll: false});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -160,7 +160,7 @@ function process_hotkey(e) {
|
|||||||
return true;
|
return true;
|
||||||
case 32: // Spacebar
|
case 32: // Spacebar
|
||||||
case 34: // Page Down
|
case 34: // Page Down
|
||||||
if (at_bottom_of_viewport() && !current_msg_list.empty()) {
|
if (viewport.at_bottom() && !current_msg_list.empty()) {
|
||||||
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
|
current_msg_list.select_id(current_msg_list.last().id, {then_scroll: false});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -6,6 +6,18 @@ var height;
|
|||||||
var width;
|
var width;
|
||||||
var in_stoppable_autoscroll = false;
|
var in_stoppable_autoscroll = false;
|
||||||
|
|
||||||
|
exports.at_top = function () {
|
||||||
|
return (jwindow.scrollTop() <= 0);
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.at_bottom = function () {
|
||||||
|
// outerHeight(true): Include margin
|
||||||
|
var bottom = jwindow.scrollTop() + jwindow.height();
|
||||||
|
var window_size = $(document).height();
|
||||||
|
|
||||||
|
return bottom >= window_size;
|
||||||
|
};
|
||||||
|
|
||||||
exports.scrollTop = function viewport_scrollTop () {
|
exports.scrollTop = function viewport_scrollTop () {
|
||||||
return jwindow.scrollTop.apply(jwindow, arguments);
|
return jwindow.scrollTop.apply(jwindow, arguments);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1120,15 +1120,6 @@ setInterval(function () {
|
|||||||
watchdog_time = new_time;
|
watchdog_time = new_time;
|
||||||
}, 5000);
|
}, 5000);
|
||||||
|
|
||||||
function at_top_of_viewport() {
|
|
||||||
return (viewport.scrollTop() === 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
function at_bottom_of_viewport() {
|
|
||||||
// outerHeight(true): Include margin
|
|
||||||
return (viewport.scrollTop() + viewport.height() >= $("#main_div").outerHeight(true));
|
|
||||||
}
|
|
||||||
|
|
||||||
function keep_pointer_in_view() {
|
function keep_pointer_in_view() {
|
||||||
var candidate;
|
var candidate;
|
||||||
var next_row = current_msg_list.selected_row();
|
var next_row = current_msg_list.selected_row();
|
||||||
@@ -1152,8 +1143,8 @@ function keep_pointer_in_view() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! adjust(above_view_threshold, at_top_of_viewport, rows.next_visible))
|
if (! adjust(above_view_threshold, viewport.at_top, rows.next_visible))
|
||||||
adjust(below_view_threshold, at_bottom_of_viewport, rows.prev_visible);
|
adjust(below_view_threshold, viewport.at_bottom, rows.prev_visible);
|
||||||
|
|
||||||
current_msg_list.select_id(rows.id(next_row), {from_scroll: true});
|
current_msg_list.select_id(rows.id(next_row), {from_scroll: true});
|
||||||
}
|
}
|
||||||
@@ -1164,7 +1155,7 @@ function keep_pointer_in_view() {
|
|||||||
// the scrollwheel, the selection should advance until
|
// the scrollwheel, the selection should advance until
|
||||||
// I'm at the very top or the very bottom of the page.
|
// I'm at the very top or the very bottom of the page.
|
||||||
function move_pointer_at_page_top_and_bottom(delta) {
|
function move_pointer_at_page_top_and_bottom(delta) {
|
||||||
if (delta !== 0 && (at_top_of_viewport() || at_bottom_of_viewport())) {
|
if (delta !== 0 && (viewport.at_top() || viewport.at_bottom())) {
|
||||||
var next_row = current_msg_list.selected_row();
|
var next_row = current_msg_list.selected_row();
|
||||||
if (delta > 0) {
|
if (delta > 0) {
|
||||||
// Scrolling up (want older messages)
|
// Scrolling up (want older messages)
|
||||||
|
|||||||
Reference in New Issue
Block a user