From 5330fea954010addfd91fe3ac20bd391a11c90a0 Mon Sep 17 00:00:00 2001 From: Trent Mick Date: Fri, 3 Sep 2010 21:53:53 -0700 Subject: [PATCH] Ctrl+W support for the REPL FWIW, command-line style (delete back to whitespace) would be: leading = leading.replace(/\S+\s*$/, ''); --- lib/readline.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/readline.js b/lib/readline.js index 10e614f765..7629d23244 100644 --- a/lib/readline.js +++ b/lib/readline.js @@ -331,6 +331,17 @@ Interface.prototype._ttyWrite = function (b) { this._historyNext(); break; + case 23: // control-w, delete backwards to a word boundary + if (this.cursor !== 0) { + var leading = this.line.slice(0, this.cursor); + var match = leading.match(/\s?((\W+|\w+)\s*)$/); + leading = leading.slice(0, leading.length - match[1].length); + this.line = leading + this.line.slice(this.cursor, this.line.length); + this.cursor = leading.length; + this._refreshLine(); + } + break; + case 9: // tab, completion if (this.completer) { this._tabComplete();