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

Fix suggestOnly tab issue #74 #151

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ChesterYue
Copy link

Issue: #74


@kapalex 's pr: #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.
}

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 this pull request may close these issues.

None yet

1 participant