Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(Console): Improve key up/down function in Console textarea #2108

Merged
merged 1 commit into from
Jan 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading