Reduce code duplication in keep_pointer_in_view

Fixes #269.

(imported from commit 5d382c0e1493a0798fc9bd1f5a8f37e15f2ea5ef)
This commit is contained in:
Keegan McAllister
2012-11-24 02:03:17 -05:00
parent b21bdc91cb
commit a70fb98038

View File

@@ -756,25 +756,21 @@ function keep_pointer_in_view() {
if (next_message.length === 0) if (next_message.length === 0)
return; return;
if (above_view_threshold(next_message) && (!at_top_of_viewport())) { function adjust(past_threshold, at_end, advance) {
while (above_view_threshold(next_message)) { if (!past_threshold(next_message) || at_end())
candidate = rows.next_visible(next_message); return false; // try other side
if (candidate.length === 0) { while (past_threshold(next_message)) {
candidate = advance(next_message);
if (candidate.length === 0)
break; break;
} else { next_message = candidate;
next_message = candidate;
}
}
} else if (below_view_threshold(next_message) && (!at_bottom_of_viewport())) {
while (below_view_threshold(next_message)) {
candidate = rows.prev_visible(next_message);
if (candidate.length === 0) {
break;
} else {
next_message = candidate;
}
} }
return true;
} }
if (! adjust(above_view_threshold, at_top_of_viewport, rows.next_visible))
adjust(below_view_threshold, at_bottom_of_viewport, rows.prev_visible);
update_selected_message(next_message, {update_server: true}); update_selected_message(next_message, {update_server: true});
} }