-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
repl: Copying tab characters into the repl calls tabComplete #5958
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,6 +40,7 @@ function Interface(input, output, completer, terminal) { | |
} | ||
|
||
this._sawReturn = false; | ||
this.isCompletionEnabled = true; | ||
|
||
EventEmitter.call(this); | ||
var historySize; | ||
|
@@ -129,7 +130,7 @@ function Interface(input, output, completer, terminal) { | |
|
||
} else { | ||
|
||
emitKeypressEvents(input); | ||
emitKeypressEvents(input, this); | ||
|
||
// input usually refers to stdin | ||
input.on('keypress', onkeypress); | ||
|
@@ -878,7 +879,7 @@ Interface.prototype._ttyWrite = function(s, key) { | |
|
||
case 'tab': | ||
// If tab completion enabled, do that... | ||
if (typeof this.completer === 'function') { | ||
if (typeof this.completer === 'function' && this.isCompletionEnabled) { | ||
this._tabComplete(); | ||
break; | ||
} | ||
|
@@ -912,7 +913,7 @@ exports.Interface = Interface; | |
const KEYPRESS_DECODER = Symbol('keypress-decoder'); | ||
const ESCAPE_DECODER = Symbol('escape-decoder'); | ||
|
||
function emitKeypressEvents(stream) { | ||
function emitKeypressEvents(stream, iface) { | ||
if (stream[KEYPRESS_DECODER]) return; | ||
var StringDecoder = require('string_decoder').StringDecoder; // lazy load | ||
stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); | ||
|
@@ -925,6 +926,10 @@ function emitKeypressEvents(stream) { | |
var r = stream[KEYPRESS_DECODER].write(b); | ||
if (r) { | ||
for (var i = 0; i < r.length; i++) { | ||
if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) { | ||
iface.isCompletionEnabled = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
a. Document that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm... Why? We have There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahhh sorry I didn't see the checks for it 😥 All good to go if there is a docs note. |
||
} | ||
|
||
try { | ||
stream[ESCAPE_DECODER].next(r[i]); | ||
} catch (err) { | ||
|
@@ -933,6 +938,10 @@ function emitKeypressEvents(stream) { | |
stream[ESCAPE_DECODER] = emitKeys(stream); | ||
stream[ESCAPE_DECODER].next(); | ||
throw err; | ||
} finally { | ||
if (iface) { | ||
iface.isCompletionEnabled = true; | ||
} | ||
} | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now public and requires documentation https://nodejs.org/dist/latest-v6.x/docs/api/readline.html#readline_readline_emitkeypressevents_stream