From 4cffb1a305235ba91fe3eef6ffa4f72b56ff7c0f Mon Sep 17 00:00:00 2001 From: Zhengqbbb <1074059947@qq.com> Date: Wed, 30 Oct 2024 18:34:35 +0800 Subject: [PATCH] fix(plugin-inquirer): press tab or right key exit error when input no complete value --- packages/@cz-git/plugin-inquirer/src/input/index.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/@cz-git/plugin-inquirer/src/input/index.ts b/packages/@cz-git/plugin-inquirer/src/input/index.ts index 711d3b944..4abd4bd1f 100644 --- a/packages/@cz-git/plugin-inquirer/src/input/index.ts +++ b/packages/@cz-git/plugin-inquirer/src/input/index.ts @@ -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 @@ -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 = ''