repl: Auto alignment for .editor mode · nodejs/node@5bef38b · GitHub
Skip to content

Commit 5bef38b

Browse files
committed
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: #8241 Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent f8f283b commit 5bef38b

3 files changed

Lines changed: 71 additions & 2 deletions

File tree

lib/readline.js

Lines changed: 8 additions & 0 deletions

lib/repl.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -471,6 +471,15 @@ function REPLServer(prompt,
471471

472472
if (self.editorMode) {
473473
self.bufferedCommand += cmd + '\n';
474+
475+
// code alignment
476+
const matches = self._sawKeyPress ? cmd.match(/^\s+/) : null;
477+
if (matches) {
478+
const prefix = matches[0];
479+
self.inputStream.write(prefix);
480+
self.line = prefix;
481+
self.cursor = prefix.length;
482+
}
474483
self.memory(cmd);
475484
return;
476485
}

test/parallel/test-repl-.editor.js

Lines changed: 54 additions & 2 deletions

0 commit comments

Comments
 (0)