From 3a93c8cc9005b2673509277fb4526fe2fb4e47fe Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Wed, 3 Apr 2013 13:33:10 -0400 Subject: [PATCH] Fix pointer jumps on unnarrowing after certain scroll events. This appears to have been caused by our code for preventing the viewport from being recentered if you move the pointer away from the edge of the viewport from a position near the edge, which was being run even when it was not triggered by a scroll event. (imported from commit 0a4b3dcca75a6e5dbf1beb77a5249bd6a9c61341) --- zephyr/static/js/hotkey.js | 9 ++++++--- zephyr/static/js/ui.js | 2 +- zephyr/static/js/zephyr.js | 13 +++++++------ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/zephyr/static/js/hotkey.js b/zephyr/static/js/hotkey.js index 9ce57b5f4d..ee5c0f0886 100644 --- a/zephyr/static/js/hotkey.js +++ b/zephyr/static/js/hotkey.js @@ -101,9 +101,10 @@ function process_hotkey(e) { if (directional_hotkeys_id.hasOwnProperty(code)) { dirkey = directional_hotkeys_id[code]; - last_viewport_movement_direction = dirkey.direction; var next_id = dirkey.getid(); - current_msg_list.select_id(next_id, {then_scroll: true}); + last_viewport_movement_direction = dirkey.direction; + current_msg_list.select_id(next_id, {then_scroll: true, + from_scroll: true}); return true; } @@ -112,7 +113,9 @@ function process_hotkey(e) { last_viewport_movement_direction = dirkey.direction; next_row = dirkey.getrow(current_msg_list.selected_row()); if (next_row.length !== 0) { - current_msg_list.select_id(rows.id(next_row), {then_scroll: true}); + current_msg_list.select_id(rows.id(next_row), + {then_scroll: true, + from_scroll: true}); } if ((next_row.length === 0) && (code === 40 || code === 106)) { // At the last message, scroll to the bottom so we have diff --git a/zephyr/static/js/ui.js b/zephyr/static/js/ui.js index be6980b18a..b6ed7d7c10 100644 --- a/zephyr/static/js/ui.js +++ b/zephyr/static/js/ui.js @@ -969,7 +969,7 @@ $(function () { row.addClass('selected_message'); if (event.then_scroll) { - recenter_view(row); + recenter_view(row, event.from_scroll); } }); diff --git a/zephyr/static/js/zephyr.js b/zephyr/static/js/zephyr.js index 6dc4b97c7d..6761cd1940 100644 --- a/zephyr/static/js/zephyr.js +++ b/zephyr/static/js/zephyr.js @@ -95,7 +95,7 @@ function below_view_threshold(message) { return message.offset().top > viewport.scrollTop() + viewport.height() * 2 / 3; } -function recenter_view(message) { +function recenter_view(message, from_scroll) { // Barnowl-style recentering: if the pointer is too high, center // in the middle of the screen. If the pointer is too low, center // on the 1/5-mark. @@ -105,10 +105,11 @@ function recenter_view(message) { var selected_row = current_msg_list.selected_row(); var selected_row_top = selected_row.offset().top; - if ((above_view_threshold(message, true) && - (last_viewport_movement_direction >= 0)) || - (below_view_threshold(message) && - (last_viewport_movement_direction <= 0))) { + if (from_scroll !== undefined && from_scroll && + ((above_view_threshold(message, true) && + (last_viewport_movement_direction >= 0)) || + (below_view_threshold(message) && + (last_viewport_movement_direction <= 0)))) { // 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 @@ -985,7 +986,7 @@ function keep_pointer_in_view() { if (! adjust(above_view_threshold, at_top_of_viewport, rows.next_visible)) adjust(below_view_threshold, at_bottom_of_viewport, rows.prev_visible); - current_msg_list.select_id(rows.id(next_row)); + current_msg_list.select_id(rows.id(next_row), {from_scroll: true}); } // The idea here is when you've scrolled to the very