navigate: Correct handling of limited fetched content.

This correctly avoids pageup/pagedown scrolling past already rendered
content, while also always making progress, which the previous logic
introduced in d8ec141de2 might do, at
least in degenerate cases with very small render windows.

I'm not sure this change has any effect in practice with current
render window values, but it does fix a bug if I set the maximum
render window size to 20.
This commit is contained in:
Tim Abbott 2024-02-05 19:16:46 -08:00
parent b9af5ce86e
commit a8698c08ca
2 changed files with 27 additions and 12 deletions

View File

@ -1439,6 +1439,10 @@ export class MessageListView {
this.message_containers.clear();
}
last_rendered_message() {
return this.list.data._items[this._render_win_end - 1];
}
is_fetched_end_rendered() {
return this._render_win_end === this.list.num_items();
}
@ -1452,6 +1456,10 @@ export class MessageListView {
return this.is_fetched_end_rendered() && this.list.data.fetch_status.has_found_newest();
}
first_rendered_message() {
return this.list.data._items[this._render_win_start];
}
is_fetched_start_rendered() {
return this._render_win_start === 0;
}

View File

@ -100,24 +100,31 @@ export function page_down_the_right_amount() {
}
export function page_up() {
if (
message_viewport.at_rendered_top() &&
!message_lists.current.visibly_empty() &&
message_lists.current.view.is_fetched_start_rendered()
) {
message_lists.current.select_id(message_lists.current.first().id, {then_scroll: false});
if (message_viewport.at_rendered_top() && !message_lists.current.visibly_empty()) {
if (message_lists.current.view.is_fetched_start_rendered()) {
message_lists.current.select_id(message_lists.current.first().id, {then_scroll: false});
} else {
message_lists.current.select_id(
message_lists.current.view.first_rendered_message().id,
{
then_scroll: false,
},
);
}
} else {
page_up_the_right_amount();
}
}
export function page_down() {
if (
message_viewport.at_rendered_bottom() &&
!message_lists.current.visibly_empty() &&
message_lists.current.view.is_fetched_end_rendered()
) {
message_lists.current.select_id(message_lists.current.last().id, {then_scroll: false});
if (message_viewport.at_rendered_bottom() && !message_lists.current.visibly_empty()) {
if (message_lists.current.view.is_fetched_end_rendered()) {
message_lists.current.select_id(message_lists.current.last().id, {then_scroll: false});
} else {
message_lists.current.select_id(message_lists.current.view.last_rendered_message().id, {
then_scroll: false,
});
}
unread_ops.process_visible();
} else {
page_down_the_right_amount();