Skip to content

Commit

Permalink
feat(Console): Improve key up/down in Console with multi-line input/h…
Browse files Browse the repository at this point in the history
…istory (#2108)
  • Loading branch information
meteyou authored Jan 3, 2025
1 parent e73c221 commit 05e9e41
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/components/inputs/ConsoleTextarea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand All @@ -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) {
Expand Down

0 comments on commit 05e9e41

Please sign in to comment.