From 3a97a89d2084d9c798ef49e1748bc444ce5a539a Mon Sep 17 00:00:00 2001 From: Dane Everitt Date: Sat, 21 Jul 2018 16:22:41 -0700 Subject: [PATCH] Add command history --- .../server/subpages/ConsolePage.vue | 26 +++++++++++++++++++ webpack.config.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/resources/assets/scripts/components/server/subpages/ConsolePage.vue b/resources/assets/scripts/components/server/subpages/ConsolePage.vue index 9593b7aea..9d0b61124 100644 --- a/resources/assets/scripts/components/server/subpages/ConsolePage.vue +++ b/resources/assets/scripts/components/server/subpages/ConsolePage.vue @@ -13,6 +13,7 @@ ref="command" v-model="command" v-on:keyup.enter="sendCommand" + v-on:keydown="handleArrowKey" > @@ -53,13 +54,38 @@ } }), command: '', + commandHistory: [], + commandHistoryIndex: -1, }; }, methods: { sendCommand: function () { + this.commandHistory.unshift(this.command); this.$parent.$emit('send-command', this.command); this.command = ''; + }, + + /** + * Handle a user pressing up/down arrows when in the command field to scroll through thier + * command history for this server. + * + * @param {KeyboardEvent} e + */ + handleArrowKey: function (e) { + if (['ArrowUp', 'ArrowDown'].indexOf(e.key) < 0 || e.key === 'ArrowDown' && this.commandHistoryIndex < 0) { + return; + } + + e.preventDefault(); + e.stopPropagation(); + + if (e.key === 'ArrowUp' && (this.commandHistoryIndex + 1 > (this.commandHistory.length - 1))) { + return; + } + + this.commandHistoryIndex += (e.key === 'ArrowUp') ? 1 : -1; + this.command = this.commandHistoryIndex < 0 ? '' : this.commandHistory[this.commandHistoryIndex]; } } }; diff --git a/webpack.config.js b/webpack.config.js index d0e4ac41e..1ad40a429 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -68,7 +68,7 @@ const productionPlugins = [ module.exports = { mode: process.env.NODE_ENV, - devtool: process.env.NODE_ENV === 'production' ? false : 'eval-source-map', + devtool: process.env.NODE_ENV === 'production' ? false : 'inline-source-map', performance: { hints: false, },