From c619be59175360040af49ed6ec4625c0c63283bd Mon Sep 17 00:00:00 2001 From: mappu Date: Sun, 5 Feb 2017 17:49:59 +1300 Subject: [PATCH] client: chat scrollback: clamp to edges rather than wrapping --- client/dcwebui.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/client/dcwebui.js b/client/dcwebui.js index ef9fdf0..7e99de5 100644 --- a/client/dcwebui.js +++ b/client/dcwebui.js @@ -698,9 +698,16 @@ var scrollback_move = function(delta) { } 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 { - 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];