Add command history

This commit is contained in:
Dane Everitt 2018-07-21 16:22:41 -07:00
parent 38d50c8fc2
commit 3a97a89d20
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 27 additions and 1 deletions

View file

@ -13,6 +13,7 @@
ref="command" ref="command"
v-model="command" v-model="command"
v-on:keyup.enter="sendCommand" v-on:keyup.enter="sendCommand"
v-on:keydown="handleArrowKey"
> >
</div> </div>
</div> </div>
@ -53,13 +54,38 @@
} }
}), }),
command: '', command: '',
commandHistory: [],
commandHistoryIndex: -1,
}; };
}, },
methods: { methods: {
sendCommand: function () { sendCommand: function () {
this.commandHistory.unshift(this.command);
this.$parent.$emit('send-command', this.command); this.$parent.$emit('send-command', this.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];
} }
} }
}; };

View file

@ -68,7 +68,7 @@ const productionPlugins = [
module.exports = { module.exports = {
mode: process.env.NODE_ENV, 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: { performance: {
hints: false, hints: false,
}, },