diff --git a/client/components/ChatInput.vue b/client/components/ChatInput.vue index b523f3df..874cbe73 100644 --- a/client/components/ChatInput.vue +++ b/client/components/ChatInput.vue @@ -115,6 +115,29 @@ export default { } }); + inputTrap.bind(["up", "down"], (e, key) => { + if (e.target.selectionStart !== e.target.selectionEnd) { + return; + } + + if (this.channel.inputHistoryPosition === 0) { + this.channel.inputHistory[this.channel.inputHistoryPosition] = this.channel.pendingMessage; + } + + if (key === "up") { + if (this.channel.inputHistoryPosition < this.channel.inputHistory.length - 1) { + this.channel.inputHistoryPosition++; + } + } else if (this.channel.inputHistoryPosition > 0) { + this.channel.inputHistoryPosition--; + } + + this.channel.pendingMessage = this.$refs.input.value = this.channel.inputHistory[this.channel.inputHistoryPosition]; + this.setInputSize(); + + return false; + }); + if (this.$root.fileUploadEnabled) { upload.initialize(); } @@ -125,6 +148,7 @@ export default { methods: { setPendingMessage(e) { this.channel.pendingMessage = e.target.value; + this.channel.inputHistoryPosition = 0; this.setInputSize(); }, setInputSize() { @@ -166,10 +190,16 @@ export default { return false; } + this.channel.inputHistoryPosition = 0; this.channel.pendingMessage = ""; this.$refs.input.value = ""; this.setInputSize(); + // Store new message in history if last message isn't already equal + if (this.channel.inputHistory[1] !== text) { + this.channel.inputHistory.splice(1, 0, text); + } + if (text[0] === "/") { const args = text.substr(1).split(" "); const cmd = args.shift().toLowerCase(); diff --git a/client/js/vue.js b/client/js/vue.js index 2f843a71..9107760c 100644 --- a/client/js/vue.js +++ b/client/js/vue.js @@ -71,6 +71,9 @@ function findChannel(id) { } function initChannel(channel) { + channel.pendingMessage = ""; + channel.inputHistoryPosition = 0; + channel.inputHistory = [""]; channel.historyLoading = false; channel.scrolledToBottom = true;