From 48cda57d84f73b045ce093cbfd08eb6e6dc6097c Mon Sep 17 00:00:00 2001 From: Waseem Daher Date: Wed, 10 Oct 2012 14:20:31 -0400 Subject: [PATCH] Fix issue where arrowing-down near end of page would skip a message. We had this fascinating behavior where pressing a down arrow near the end of the page would advance the pointer, call recenter_view, which would trigger a scroll event, which would call keep_pointer_in_view, which would notice that we were at the end of the page and advance the pointer again! I split out that last part into its own function which is only called on mousewheel events. (imported from commit bc85443e762356e3055f8f88585940a1f11f9124) --- tools/jslint/check-all.js | 3 ++- zephyr/static/js/ui.js | 10 ++++++++-- zephyr/static/js/zephyr.js | 10 ++++++++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/tools/jslint/check-all.js b/tools/jslint/check-all.js index 7923706a4d..ce916ce642 100644 --- a/tools/jslint/check-all.js +++ b/tools/jslint/check-all.js @@ -39,7 +39,8 @@ var globals = // zephyr.js + ' message_array message_dict' + ' status_classes clear_table add_to_table instance_list' - + ' keep_pointer_in_view respond_to_message' + + ' keep_pointer_in_view move_pointer_at_page_top_and_bottom' + + ' respond_to_message' + ' select_message select_message_by_id' + ' scroll_to_selected select_and_show_by_id' + ' selected_message selected_message_id' diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index 94322d5a9b..02926aee5d 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -138,9 +138,15 @@ $(function () { sub_from_home(compose_class_name(), $('#class-nosub')); }); - var throttled_scrollhandler = $.throttle(50, function() { + var throttled_scrollhandler = $.throttle(50, function(e) { if ($('#home').hasClass('active')) { - keep_pointer_in_view(); + keep_pointer_in_view(); + if (e.type === 'mousewheel') { + // If we mousewheel (or trackpad-scroll) when + // we're at the top and bottom of the page, the + // pointer may still want to move. + move_pointer_at_page_top_and_bottom(); + } } }); $(window).mousewheel(throttled_scrollhandler); diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index ddc9a2ab80..020ac73708 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -515,6 +515,16 @@ function keep_pointer_in_view() { } } } + update_selected_message(next_message); +} + +// The idea here is when you've scrolled to the very +// bottom of the page, e.g., the scroll handler isn't +// going to fire anymore. But if I continue to use +// the scrollwheel, the selection should advance until +// I'm at the very top or the very bottom of the page. +function move_pointer_at_page_top_and_bottom() { + var next_message = get_message_row(selected_message_id); if (at_top_of_viewport() && (parseInt(get_id(next_message), 10) > parseInt(get_id(get_first_visible()), 10))) {