| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -354,6 +354,13 @@ a `'resize'` event on the `output` if/when the columns ever change | |||
| 354 | 354 | ||
| 355 | 355 | Move cursor to the specified position in a given TTY stream. | |
| 356 | 356 | ||
| 357 | + ## readline.emitKeypressEvents(stream[, interface]) | ||
| 358 | + | ||
| 359 | + Causes `stream` to begin emitting `'keypress'` events corresponding to its | ||
| 360 | + input. | ||
| 361 | + Optionally, `interface` specifies a `readline.Interface` instance for which | ||
| 362 | + autocompletion is disabled when copy-pasted input is detected. | ||
| 363 | + | ||
| 357 | 364 | ## readline.moveCursor(stream, dx, dy) | |
| 358 | 365 | ||
| 359 | 366 | Move cursor relative to it's current position in a given TTY stream. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,7 @@ function Interface(input, output, completer, terminal) { | |||
| 36 | 36 | } | |
| 37 | 37 | ||
| 38 | 38 | this._sawReturn = false; | |
| 39 | + this.isCompletionEnabled = true; | ||
| 39 | 40 | ||
| 40 | 41 | EventEmitter.call(this); | |
| 41 | 42 | var historySize; | |
@@ -122,7 +123,7 @@ function Interface(input, output, completer, terminal) { | |||
| 122 | 123 | ||
| 123 | 124 | } else { | |
| 124 | 125 | ||
| 125 | - exports.emitKeypressEvents(input); | ||
| 126 | + exports.emitKeypressEvents(input, this); | ||
| 126 | 127 | ||
| 127 | 128 | // input usually refers to stdin | |
| 128 | 129 | input.on('keypress', onkeypress); | |
@@ -868,7 +869,7 @@ Interface.prototype._ttyWrite = function(s, key) { | |||
| 868 | 869 | ||
| 869 | 870 | case 'tab': | |
| 870 | 871 | // If tab completion enabled, do that... | |
| 871 | - if (typeof this.completer === 'function') { | ||
| 872 | + if (typeof this.completer === 'function' && this.isCompletionEnabled) { | ||
| 872 | 873 | this._tabComplete(); | |
| 873 | 874 | break; | |
| 874 | 875 | } | |
@@ -902,7 +903,7 @@ exports.Interface = Interface; | |||
| 902 | 903 | const KEYPRESS_DECODER = Symbol('keypress-decoder'); | |
| 903 | 904 | const ESCAPE_DECODER = Symbol('escape-decoder'); | |
| 904 | 905 | ||
| 905 | - function emitKeypressEvents(stream) { | ||
| 906 | + function emitKeypressEvents(stream, iface) { | ||
| 906 | 907 | if (stream[KEYPRESS_DECODER]) return; | |
| 907 | 908 | var StringDecoder = require('string_decoder').StringDecoder; // lazy load | |
| 908 | 909 | stream[KEYPRESS_DECODER] = new StringDecoder('utf8'); | |
@@ -915,6 +916,10 @@ function emitKeypressEvents(stream) { | |||
| 915 | 916 | var r = stream[KEYPRESS_DECODER].write(b); | |
| 916 | 917 | if (r) { | |
| 917 | 918 | for (var i = 0; i < r.length; i++) { | |
| 919 | + if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) { | ||
| 920 | + iface.isCompletionEnabled = false; | ||
| 921 | + } | ||
| 922 | + | ||
| 918 | 923 | try { | |
| 919 | 924 | stream[ESCAPE_DECODER].next(r[i]); | |
| 920 | 925 | } catch (err) { | |
@@ -923,6 +928,10 @@ function emitKeypressEvents(stream) { | |||
| 923 | 928 | stream[ESCAPE_DECODER] = emitKeys(stream); | |
| 924 | 929 | stream[ESCAPE_DECODER].next(); | |
| 925 | 930 | throw err; | |
| 931 | + } finally { | ||
| 932 | + if (iface) { | ||
| 933 | + iface.isCompletionEnabled = true; | ||
| 934 | + } | ||
| 926 | 935 | } | |
| 927 | 936 | } | |
| 928 | 937 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -208,7 +208,9 @@ function isWarned(emitter) { | |||
| 208 | 208 | assert.strictEqual(called, false); | |
| 209 | 209 | called = true; | |
| 210 | 210 | }); | |
| 211 | - fi.emit('data', '\tfo\to\t'); | ||
| 211 | + for (var character of '\tfo\to\t') { | ||
| 212 | + fi.emit('data', character); | ||
| 213 | + } | ||
| 212 | 214 | fi.emit('data', '\n'); | |
| 213 | 215 | assert.ok(called); | |
| 214 | 216 | rli.close(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments