mirror of https://github.com/zulip/zulip.git
Move recenter_view to viewport.js.
This commit is contained in:
parent
4be20c4b4a
commit
89d743787e
|
@ -105,7 +105,7 @@ exports.cycle_stream = function (direction) {
|
|||
exports.scroll_to_selected = function () {
|
||||
var selected_row = current_msg_list.selected_row();
|
||||
if (selected_row && (selected_row.length !== 0)) {
|
||||
recenter_view(selected_row);
|
||||
viewport.recenter_view(selected_row);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -76,7 +76,7 @@ exports.fast_forward_pointer = function () {
|
|||
};
|
||||
|
||||
exports.keep_pointer_in_view = function () {
|
||||
// See recenter_view() for related logic to keep the pointer onscreen.
|
||||
// See viewport.recenter_view() for related logic to keep the pointer onscreen.
|
||||
// This function mostly comes into place for mouse scrollers, and it
|
||||
// keeps the pointer in view. For people who purely scroll with the
|
||||
// mouse, the pointer is kind of meaningless to them, but keyboard
|
||||
|
|
|
@ -459,7 +459,7 @@ $(function () {
|
|||
// Scroll to place the message within the current view;
|
||||
// but if this is the initial placement of the pointer,
|
||||
// just place it in the very center
|
||||
recenter_view(row, {from_scroll: event.from_scroll,
|
||||
viewport.recenter_view(row, {from_scroll: event.from_scroll,
|
||||
force_center: event.previously_selected === -1});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -285,6 +285,47 @@ exports.user_initiated_animate_scroll = function (scroll_amount) {
|
|||
});
|
||||
};
|
||||
|
||||
exports.recenter_view = function (message, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
// Barnowl-style recentering: if the pointer is too high, move it to
|
||||
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
|
||||
// See keep_pointer_in_view() in pointer.js for related logic to keep the pointer onscreen.
|
||||
|
||||
var viewport_info = exports.message_viewport_info();
|
||||
var top_threshold = viewport_info.visible_top;
|
||||
|
||||
var bottom_threshold = viewport_info.visible_top + viewport_info.visible_height;
|
||||
|
||||
var message_top = message.offset().top;
|
||||
var message_height = message.outerHeight(true);
|
||||
var message_bottom = message_top + message_height;
|
||||
|
||||
var is_above = message_top < top_threshold;
|
||||
var is_below = message_bottom > bottom_threshold;
|
||||
|
||||
if (opts.from_scroll) {
|
||||
// If the message you're trying to center on is already in view AND
|
||||
// you're already trying to move in the direction of that message,
|
||||
// don't try to recenter. This avoids disorienting jumps when the
|
||||
// pointer has gotten itself outside the threshold (e.g. by
|
||||
// autoscrolling).
|
||||
if (is_above && exports.last_movement_direction >= 0) {
|
||||
return;
|
||||
}
|
||||
if (is_below && exports.last_movement_direction <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_above || opts.force_center) {
|
||||
exports.set_message_position(message_top, message_height, viewport_info, 1/2);
|
||||
} else if (is_below) {
|
||||
exports.set_message_position(message_top, message_height, viewport_info, 1/7);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
$(function () {
|
||||
jwindow = $(window);
|
||||
exports.message_pane = $(".app");
|
||||
|
|
|
@ -9,45 +9,6 @@ var queued_mark_as_read = [];
|
|||
var queued_flag_timer;
|
||||
|
||||
|
||||
function recenter_view(message, opts) {
|
||||
opts = opts || {};
|
||||
|
||||
// Barnowl-style recentering: if the pointer is too high, move it to
|
||||
// the 1/2 marks. If the pointer is too low, move it to the 1/7 mark.
|
||||
// See keep_pointer_in_view() in pointer.js for related logic to keep the pointer onscreen.
|
||||
|
||||
var viewport_info = viewport.message_viewport_info();
|
||||
var top_threshold = viewport_info.visible_top;
|
||||
|
||||
var bottom_threshold = viewport_info.visible_top + viewport_info.visible_height;
|
||||
|
||||
var message_top = message.offset().top;
|
||||
var message_height = message.outerHeight(true);
|
||||
var message_bottom = message_top + message_height;
|
||||
|
||||
var is_above = message_top < top_threshold;
|
||||
var is_below = message_bottom > bottom_threshold;
|
||||
|
||||
if (opts.from_scroll) {
|
||||
// If the message you're trying to center on is already in view AND
|
||||
// you're already trying to move in the direction of that message,
|
||||
// don't try to recenter. This avoids disorienting jumps when the
|
||||
// pointer has gotten itself outside the threshold (e.g. by
|
||||
// autoscrolling).
|
||||
if (is_above && viewport.last_movement_direction >= 0) {
|
||||
return;
|
||||
}
|
||||
if (is_below && viewport.last_movement_direction <= 0) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_above || opts.force_center) {
|
||||
viewport.set_message_position(message_top, message_height, viewport_info, 1/2);
|
||||
} else if (is_below) {
|
||||
viewport.set_message_position(message_top, message_height, viewport_info, 1/7);
|
||||
}
|
||||
}
|
||||
|
||||
function get_private_message_recipient(message, attr, fallback_attr) {
|
||||
var recipient, i;
|
||||
|
|
|
@ -54,7 +54,7 @@ var globals =
|
|||
|
||||
// zulip.js
|
||||
+ ' home_msg_list current_msg_list'
|
||||
+ ' respond_to_message recenter_view'
|
||||
+ ' respond_to_message'
|
||||
+ ' get_private_message_recipient'
|
||||
+ ' process_loaded_for_unread'
|
||||
+ ' recent_subjects unread_subjects'
|
||||
|
|
Loading…
Reference in New Issue