| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -357,10 +357,12 @@ a `'resize'` event on the `output` if/when the columns ever change | |||
| 357 | 357 | ||
| 358 | 358 | Move cursor to the specified position in a given TTY stream. | |
| 359 | 359 | ||
| 360 | - ## readline.emitKeypressEvents(stream) | ||
| 360 | + ## readline.emitKeypressEvents(stream[, interface]) | ||
| 361 | 361 | ||
| 362 | 362 | Causes `stream` to begin emitting `'keypress'` events corresponding to its | |
| 363 | 363 | input. | |
| 364 | + Optionally, `interface` specifies a `readline.Interface` instance for which | ||
| 365 | + autocompletion is disabled when copy-pasted input is detected. | ||
| 364 | 366 | ||
| 365 | 367 | Note that the stream, if it is a TTY, needs to be in raw mode: | |
| 366 | 368 | ```js | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,6 +41,7 @@ function Interface(input, output, completer, terminal) { | |||
| 41 | 41 | } | |
| 42 | 42 | ||
| 43 | 43 | this._sawReturn = false; | |
| 44 | + this.isCompletionEnabled = true; | ||
| 44 | 45 | ||
| 45 | 46 | EventEmitter.call(this); | |
| 46 | 47 | var historySize; | |
@@ -130,7 +131,7 @@ function Interface(input, output, completer, terminal) { | |||
| 130 | 131 | ||
| 131 | 132 | } else { | |
| 132 | 133 | ||
| 133 | - emitKeypressEvents(input); | ||
| 134 | + emitKeypressEvents(input, this); | ||
| 134 | 135 | ||
| 135 | 136 | // input usually refers to stdin | |
| 136 | 137 | input.on('keypress', onkeypress); | |
@@ -883,7 +884,7 @@ Interface.prototype._ttyWrite = function(s, key) { | |||
| 883 | 884 | ||
| 884 | 885 | case 'tab': | |
| 885 | 886 | // If tab completion enabled, do that... | |
| 886 | - if (typeof this.completer === 'function') { | ||
| 887 | + if (typeof this.completer === 'function' && this.isCompletionEnabled) { | ||
| 887 | 888 | this._tabComplete(); | |
| 888 | 889 | break; | |
| 889 | 890 | } | |
@@ -917,7 +918,7 @@ exports.Interface = Interface; | |||
| 917 | 918 | const KEYPRESS_DECODER = Symbol('keypress-decoder'); | |
| 918 | 919 | const ESCAPE_DECODER = Symbol('escape-decoder'); | |
| 919 | 920 | ||
| 920 | - function emitKeypressEvents(stream) { | ||
| 921 | + function emitKeypressEvents(stream, iface) { | ||
| 921 | 922 | if (stream[KEYPRESS_DECODER]) return; | |
| 922 | 923 | var StringDecoder = require('string_decoder').StringDecoder; // lazy load | |
| 923 | 924 | stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); | |
@@ -930,6 +931,10 @@ function emitKeypressEvents(stream) { | |||
| 930 | 931 | var r = stream[KEYPRESS_DECODER].write(b); | |
| 931 | 932 | if (r) { | |
| 932 | 933 | for (var i = 0; i < r.length; i++) { | |
| 934 | + if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) { | ||
| 935 | + iface.isCompletionEnabled = false; | ||
| 936 | + } | ||
| 937 | + | ||
| 933 | 938 | try { | |
| 934 | 939 | stream[ESCAPE_DECODER].next(r[i]); | |
| 935 | 940 | } catch (err) { | |
@@ -938,6 +943,10 @@ function emitKeypressEvents(stream) { | |||
| 938 | 943 | stream[ESCAPE_DECODER] = emitKeys(stream); | |
| 939 | 944 | stream[ESCAPE_DECODER].next(); | |
| 940 | 945 | throw err; | |
| 946 | + } finally { | ||
| 947 | + if (iface) { | ||
| 948 | + iface.isCompletionEnabled = true; | ||
| 949 | + } | ||
| 941 | 950 | } | |
| 942 | 951 | } | |
| 943 | 952 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -227,7 +227,9 @@ function isWarned(emitter) { | |||
| 227 | 227 | assert.strictEqual(called, false); | |
| 228 | 228 | called = true; | |
| 229 | 229 | }); | |
| 230 | - fi.emit('data', '\tfo\to\t'); | ||
| 230 | + for (var character of '\tfo\to\t') { | ||
| 231 | + fi.emit('data', character); | ||
| 232 | + } | ||
| 231 | 233 | fi.emit('data', '\n'); | |
| 232 | 234 | assert.ok(called); | |
| 233 | 235 | rli.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments