Skip to content

Commit

Permalink
repl: treat tab as spaces while pasting
Browse files Browse the repository at this point in the history
Fixes: #25272
  • Loading branch information
antsmartian committed Dec 30, 2018
1 parent 903630e commit e474391
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions lib/readline.js
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,7 @@ Interface.prototype._ttyWrite = function(s, key) {
s = s.toString('utf-8');

if (s) {
s = s.replace(/\t/g, ' ');
var lines = s.split(/\r\n|\n|\r/);
for (var i = 0, len = lines.length; i < len; i++) {
if (i > 0) {
Expand Down
7 changes: 4 additions & 3 deletions test/parallel/test-readline-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,20 +311,21 @@ function isWarned(emitter) {
}), delay);
}

// \t when there is no completer function should behave like an ordinary
// character
// \t when there is no completer function should be
// treated as space
{
const fi = new FakeInput();
const rli = new readline.Interface(
{ input: fi, output: fi, terminal: true }
);
let called = false;
rli.on('line', function(line) {
assert.strictEqual(line, '\t');
assert.strictEqual(line, ' var a = 5;');
assert.strictEqual(called, false);
called = true;
});
fi.emit('data', '\t');
fi.emit('data', 'var \t\ta\t=\t5;');
fi.emit('data', '\n');
assert.ok(called);
rli.close();
Expand Down

0 comments on commit e474391

Please sign in to comment.