From ff43ffda59bc04e08c7e8226a3fc15dc95dd3cbb Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 30 Dec 2024 13:48:26 +0100 Subject: [PATCH] feat(Console): Improve key up/down in Console with multi-line input/history Signed-off-by: Stefan Dej --- src/components/inputs/ConsoleTextarea.vue | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/components/inputs/ConsoleTextarea.vue b/src/components/inputs/ConsoleTextarea.vue index 604772121..cfbef57a9 100644 --- a/src/components/inputs/ConsoleTextarea.vue +++ b/src/components/inputs/ConsoleTextarea.vue @@ -16,8 +16,8 @@ :prepend-icon="isTouchDevice ? mdiChevronDoubleRight : ''" :append-icon="mdiSend" @keydown.enter.prevent.stop="doSend" - @keyup.up="onKeyUp" - @keyup.down="onKeyDown" + @keydown.up="onKeyUp" + @keydown.down="onKeyDown" @keydown.tab="onAutocomplete" @click:prepend="onAutocomplete" @click:append="doSend" /> @@ -45,6 +45,12 @@ export default class ConsoleTextarea extends Mixins(BaseMixin, ConsoleMixin) { return this.gcode?.split('\n').length ?? 1 } + getCurrentLine(): number { + const textarea = this.gcodeCommandField.$refs.input + const textBeforeCursor = textarea.value.substring(0, textarea.selectionStart) + return textBeforeCursor.split('\n').length + } + setGcode(gcode: string): void { this.gcode = gcode @@ -53,7 +59,11 @@ export default class ConsoleTextarea extends Mixins(BaseMixin, ConsoleMixin) { }) } - onKeyUp(): void { + onKeyUp(event: KeyboardEvent): void { + const currentLine = this.getCurrentLine() + if (this.rows > 1 && currentLine > 1) return + + event.preventDefault() if (this.lastCommandNumber === null && this.lastCommands.length) { this.lastCommandNumber = this.lastCommands.length - 1 this.gcode = this.lastCommands[this.lastCommandNumber] @@ -63,7 +73,12 @@ export default class ConsoleTextarea extends Mixins(BaseMixin, ConsoleMixin) { } } - onKeyDown(): void { + onKeyDown(event: KeyboardEvent): void { + const currentLine = this.getCurrentLine() + if (this.rows > currentLine) return + + event.preventDefault() + if (this.lastCommandNumber === null) return if (this.lastCommandNumber < this.lastCommands.length - 1) {