subs: Fix jerky stream subscriptions scrolling with up/down keys.

Fixes #4230.
This commit is contained in:
Cynthia Lin
2017-09-21 16:37:20 -07:00
committed by Tim Abbott
parent 88bec16452
commit 395a71a433

View File

@@ -442,14 +442,39 @@ exports.change_state = (function () {
} else if (hash.arguments[0] === "all") {
components.toggle.lookup("stream-filter-toggle").goto("all-streams");
} else if (hash.arguments[0] === "subscribed") {
components.toggle.lookup("stream-filter-toggle").goto("subscribed"
);
components.toggle.lookup("stream-filter-toggle").goto("subscribed");
// if the first argument is a valid number.
} else if (/\d+/.test(hash.arguments[0])) {
var $stream_row = $(".stream-row[data-stream-id='" + hash.arguments[0] + "']");
var top = $stream_row.click()[0].offsetTop;
var stream_row = $(".stream-row[data-stream-id='" + hash.arguments[0] + "']");
var streams_list = $(".streams-list")[0];
$(".streams-list").animate({ scrollTop: top }, 200);
get_active_data().row.removeClass("active");
stream_row.addClass("active");
if ($(".stream-row:not(.notdisplayed):first")[0] === stream_row[0]) {
streams_list.scrollTop = 0;
}
if ($(".stream-row:not(.notdisplayed):last")[0] === stream_row[0]) {
streams_list.scrollTop = streams_list.scrollHeight - $(".streams-list").height();
}
if (stream_row.position().top < 70) {
streams_list.scrollTop -= streams_list.clientHeight / 2;
}
var dist_from_top = stream_row.position().top;
var total_dist = dist_from_top + stream_row[0].clientHeight;
var dist_from_bottom = streams_list.clientHeight - total_dist;
if (dist_from_bottom < -4) {
streams_list.scrollTop += streams_list.clientHeight / 2;
}
setTimeout(function () {
if (hash.arguments[0] === get_active_data().id) {
stream_row.click();
}
}, 100);
}
}
};