repl: copying tabs shouldn't trigger completion

PR-URL: https://github.com/nodejs/node/pull/5958
Fixes: https://github.com/nodejs/node/issues/5954
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
This commit is contained in:
Eugene Obrezkov 2016-05-13 10:54:31 +03:00 коммит произвёл Anna Henningsen
Родитель 830a726cff
Коммит ae178838eb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: D8B9F5AEAE84E4CF
3 изменённых файлов: 18 добавлений и 5 удалений

Просмотреть файл

@ -357,10 +357,12 @@ a `'resize'` event on the `output` if/when the columns ever change
Move cursor to the specified position in a given TTY stream.
## readline.emitKeypressEvents(stream)
## readline.emitKeypressEvents(stream[, interface])
Causes `stream` to begin emitting `'keypress'` events corresponding to its
input.
Optionally, `interface` specifies a `readline.Interface` instance for which
autocompletion is disabled when copy-pasted input is detected.
## readline.moveCursor(stream, dx, dy)

Просмотреть файл

@ -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;
}
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;
}
}
}
}

Просмотреть файл

@ -229,7 +229,9 @@ function isWarned(emitter) {
assert.strictEqual(called, false);
called = true;
});
fi.emit('data', '\tfo\to\t');
for (var character of '\tfo\to\t') {
fi.emit('data', character);
}
fi.emit('data', '\n');
assert.ok(called);
rli.close();