Open ChesterYue opened 1 year ago
Issue: #74
@kapalex 's pr: https://github.com/mokkabonna/inquirer-autocomplete-prompt/pull/122 (didn't merged by conflict) try to fix.
But involved a bug:
this.rl.input.emit('keypress', '\b', { name: 'backspace' }); if (autoCompleted.includes(this.rl.line)) { this.rl.write(autoCompleted.replace(this.rl.line, '')); // Bugged line }
Case passed
// when: this.rl.line === 'a'; autoCompleted === 'apple'; // bugged line goes to: this.rl.write('pple'); // equals to: this.rl.line = 'a' + 'pple'; // result passed: this.rl.line === 'apple' === autoCompleted
Case failed
// when: this.rl.line === 'p'; autoCompleted === 'apple'; // bugged line goes to: this.rl.write('aple'); // equals to: this.rl.line = 'a' + 'aple'; // result failed: this.rl.line === 'aaple' !== autoCompleted
This pr is inspired by his solution, fixed the issue:
this.rl.input.emit('keypress', '\b', {name: 'backspace'}); // Remove redundant tab. if (autoCompleted.includes(this.rl.line)) { this.rl.line = ''; this.rl.write(autoCompleted); this.rl.input.emit('keypress', '\b', {name: 'right'}); // Calibrate cursor to right position. }
Issue: #74
@kapalex 's pr: https://github.com/mokkabonna/inquirer-autocomplete-prompt/pull/122 (didn't merged by conflict) try to fix.
But involved a bug:
Case passed
Case failed
This pr is inspired by his solution, fixed the issue: