Skip to content

Commit

Permalink
Fix caret position after tab autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
rizzlesauce committed Nov 19, 2019
1 parent c85f3b5 commit bb82298
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
6 changes: 2 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* `autocomplete` type prompt
*/

var ansiEscapes = require('ansi-escapes');
var chalk = require('chalk');
var figures = require('figures');
var Base = require('inquirer/lib/prompts/base');
Expand Down Expand Up @@ -210,10 +209,9 @@ class AutocompletePrompt extends Base {

if (keyName === 'tab' && this.opt.suggestOnly) {
if (this.currentChoices.getChoice(this.selected)) {
this.rl.write(ansiEscapes.cursorLeft);
this.rl.clearLine();
var autoCompleted = this.currentChoices.getChoice(this.selected).value;
this.rl.write(ansiEscapes.cursorForward(autoCompleted.length));
this.rl.line = autoCompleted;
this.rl.write(autoCompleted);
this.render();
}
} else if (keyName === 'down') {
Expand Down
21 changes: 16 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
"sinon": "^4.1.2"
},
"dependencies": {
"ansi-escapes": "^3.0.0",
"chalk": "^2.0.0",
"figures": "^2.0.0",
"run-async": "^2.3.0"
Expand Down

0 comments on commit bb82298

Please sign in to comment.