summaryrefslogtreecommitdiff
path: root/lib/readline.js
diff options
context:
space:
mode:
authorPrince J Wesley <princejohnwesley@gmail.com>2016-08-24 00:05:59 +0530
committerPrince J Wesley <princejohnwesley@gmail.com>2016-08-27 16:53:59 +0530
commit5bef38b627cd9522d31d1f3ceae6655a06081ed0 (patch)
treeb18813a815b87ee969695f030a6271a832bbcc3b /lib/readline.js
parentf8f283b8f3ab9ce7d63bc473468190e15dc15a55 (diff)
downloadandroid-node-v8-5bef38b627cd9522d31d1f3ceae6655a06081ed0.tar.gz
android-node-v8-5bef38b627cd9522d31d1f3ceae6655a06081ed0.tar.bz2
android-node-v8-5bef38b627cd9522d31d1f3ceae6655a06081ed0.zip
repl: Auto alignment for .editor mode
When in `.editor` mode, current line whitespace prefixes are preserved in the subsequent line. User can hit backspace to clean the whitespace ```js node 🙈 ₹ node > .editor // Entering editor mode (^D to finish, ^C to cancel) function test() { console.log('tested!'); //On enter, cursor will be after 2 spaces _ ``` PR-URL: https://github.com/nodejs/node/pull/8241 Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib/readline.js')
-rw-r--r--lib/readline.js8
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/readline.js b/lib/readline.js
index f7591b7cc1..e45fb2938e 100644
--- a/lib/readline.js
+++ b/lib/readline.js
@@ -41,6 +41,7 @@ function Interface(input, output, completer, terminal) {
this._sawReturn = false;
this.isCompletionEnabled = true;
+ this._sawKeyPress = false;
this._previousKey = null;
EventEmitter.call(this);
@@ -247,6 +248,9 @@ Interface.prototype._addHistory = function() {
// if the history is disabled then return the line
if (this.historySize === 0) return this.line;
+ // if the trimmed line is empty then return the line
+ if (this.line.trim().length === 0) return this.line;
+
if (this.history.length === 0 || this.history[0] !== this.line) {
this.history.unshift(this.line);
@@ -947,6 +951,10 @@ function emitKeypressEvents(stream, iface) {
if (r) {
clearTimeout(timeoutId);
+ if (iface) {
+ iface._sawKeyPress = r.length === 1;
+ }
+
for (var i = 0; i < r.length; i++) {
if (r[i] === '\t' && typeof r[i + 1] === 'string' && iface) {
iface.isCompletionEnabled = false;