Skip to content

Commit

Permalink
fix(plugin-inquirer): press tab or right key exit error when input no…
Browse files Browse the repository at this point in the history
… complete value
  • Loading branch information
Zhengqbbb committed Oct 30, 2024
1 parent e7b50cc commit 4cffb1a
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/@cz-git/plugin-inquirer/src/input/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ export class CompleteInput extends Base {

if (isFinal)
appendContent = this.answer || ''

else
appendContent = this.rl.line

if (transformer)
message += transformer(appendContent, this.answers, { isFinal })

else
message += isFinal ? style.cyan(appendContent) : appendContent

Expand Down Expand Up @@ -114,14 +112,18 @@ export class CompleteInput extends Base {
}

onKeypress(e: { key: { name?: string, ctrl?: boolean }, value: string }) {
if (!this.state && (e.key.name === 'tab' || e.key.name === 'right')) {
if (
!this.state
&& this.completeValue
&& (e.key.name === 'tab' || e.key.name === 'right')
) {
// NOTE: the ansi cursor not work
this.rl.write(ansiEscapes.cursorLeft)
this.rl.write(ansiEscapes.cursorForward(this.completeValue?.length))
this.rl.write(ansiEscapes.cursorForward(this.completeValue.length))
// @ts-expect-error
this.rl.line = this.completeValue
// @ts-expect-error
this.rl.cursor = this.completeValue?.length
this.rl.cursor = this.completeValue.length
}
this.state = 'touched'
this.completeValue = ''
Expand Down

0 comments on commit 4cffb1a

Please sign in to comment.