Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Default value for editor prompt not written to file (old API) #1405

Closed
mensah-j opened this issue May 14, 2024 · 0 comments · Fixed by #1406
Closed

Default value for editor prompt not written to file (old API) #1405

mensah-j opened this issue May 14, 2024 · 0 comments · Fixed by #1406

Comments

@mensah-j
Copy link
Contributor

Description

The value of the default property is not written to the temporary file when waitUserInput is set to false.

Reproduction

Using vi :

import inquirer from "inquirer";

process.env.EDITOR = "vi";

const answer = await inquirer.prompt({
  type: "editor",
  name: "value",
  message: "you shouldn't see this unless your message wasn't validated!",
  default: "replace this with your own message",
  validate(text) {
    if (!text) {
      return "you have to type something";
    }
    return true;
  },
  waitUserInput: false,
});

console.log(answer);

Expected Behavior

For vi to open with the given default contents.

Actual Behavior

The opened file is empty (furthermore, the prompt "Press <enter> to launch your preferred editor" is overlaid on top of the editing area).

Cause

The feature introduced in #1150 adds the waitUserInput flag. The implementation can be viewed at this link.

  1. The external editor is opened before the default value can be copied over to this.currentText.
  2. The initial render method is still called even though the external editor is immediately opened.

Proposed Solution

The conditional should be moved after this.currentText is set, and this.render should only be called if waitUserInput is set to true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant