client: chat scrollback: clamp to edges rather than wrapping

This commit is contained in:
mappu 2017-02-05 17:49:59 +13:00
parent afd190b7cc
commit c619be5917

View File

@ -698,9 +698,16 @@ var scrollback_move = function(delta) {
} }
if (chat_scrollback_index === -1) { if (chat_scrollback_index === -1) {
chat_scrollback_index = (delta === 1) ? 0 : chat_scrollback.length - 1; chat_scrollback_index = chat_scrollback.length - 1; // always starts at most recent message
} else { } else {
chat_scrollback_index = negmod(chat_scrollback_index + delta, chat_scrollback.length); chat_scrollback_index += delta;
// clamp
if (chat_scrollback_index === -1) {
chat_scrollback_index = 0;
} else if (chat_scrollback_index === chat_scrollback.length) {
chat_scrollback_index = chat_scrollback.length - 1;
}
} }
$("#chatbox").value = chat_scrollback[chat_scrollback_index]; $("#chatbox").value = chat_scrollback[chat_scrollback_index];