From c66f9c885e0d09dbb64603d9a2ea11082695decd Mon Sep 17 00:00:00 2001 From: Nachtalb Date: Fri, 30 Apr 2021 23:53:57 +0200 Subject: [PATCH] Only scroll history when cursor is on first or last row Needs to be on first to go up and on last to go down --- client/components/ChatInput.vue | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/client/components/ChatInput.vue b/client/components/ChatInput.vue index d12b9405..35c68b7d 100644 --- a/client/components/ChatInput.vue +++ b/client/components/ChatInput.vue @@ -140,18 +140,28 @@ export default { return; } + const onRow = ( + this.$refs.input.value.slice(null, this.$refs.input.selectionStart).match(/\n/g) || + [] + ).length; + const totalRows = (this.$refs.input.value.match(/\n/g) || []).length; + const {channel} = this; if (channel.inputHistoryPosition === 0) { channel.inputHistory[channel.inputHistoryPosition] = channel.pendingMessage; } - if (key === "up") { + if (key === "up" && onRow === 0) { if (channel.inputHistoryPosition < channel.inputHistory.length - 1) { channel.inputHistoryPosition++; + } else { + return; } - } else if (channel.inputHistoryPosition > 0) { + } else if (key === "down" && channel.inputHistoryPosition > 0 && onRow === totalRows) { channel.inputHistoryPosition--; + } else { + return; } channel.pendingMessage = channel.inputHistory[channel.inputHistoryPosition];