repl: add possibility to edit multiline commands while adding them
Summary
This PR builds upon the multiline editing support added to the REPL history in #57400, enhancing it with the ability to edit multiline input as you're writing it, before it even reaches the history.
Key Features
-
Inline Multiline Editing: You can now insert, delete, edit, and split lines while composing a REPL command. This brings a more fluid editing experience, similar to what you'd expect from a basic code editor. See the GIF below for a demo.
-
TTY-only Support: This feature makes heavy use of cursor movement to efficiently draw and clear parts of the current input. As a result, it currently only works in TTY environments.
-
Unchanged Execution Behavior: Pressing
Enterbehaves as usual:- If the current input is a complete and valid command, it executes.
- If not, a new line is added, continuing multiline input.
-
Limitations:
- If you want to insert a new line in the middle of a complete multiline command, you’ll need to first make the command incomplete (e.g. by removing a closing
}or`). - The logic for inserting new lines in complete commands is in place, but I ran into trouble capturing a reliable shortcut like
Shift + Enter. I’ve left a TODO to revisit this and debug further.
- If you want to insert a new line in the middle of a complete multiline command, you’ll need to first make the command incomplete (e.g. by removing a closing
EDIT
Implemented vertical cursor movement as well
Codecov Report
Attention: Patch coverage is 99.54751% with 1 line in your changes missing coverage. Please review.
Project coverage is 90.22%. Comparing base (
c11c7be) to head (1030ce5). Report is 455 commits behind head on main.
| Files with missing lines | Patch % | Lines |
|---|---|---|
| lib/internal/readline/interface.js | 99.48% | 1 Missing :warning: |
Additional details and impacted files
@@ Coverage Diff @@
## main #58003 +/- ##
==========================================
- Coverage 90.24% 90.22% -0.02%
==========================================
Files 630 630
Lines 185788 186589 +801
Branches 36429 36639 +210
==========================================
+ Hits 167659 168358 +699
- Misses 11004 11051 +47
- Partials 7125 7180 +55
| Files with missing lines | Coverage Δ | |
|---|---|---|
| lib/internal/readline/utils.js | 98.33% <100.00%> (+0.06%) |
:arrow_up: |
| lib/repl.js | 94.98% <100.00%> (-0.05%) |
:arrow_down: |
| lib/internal/readline/interface.js | 97.25% <99.48%> (+0.45%) |
:arrow_up: |
:rocket: New features to boost your workflow:
- :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
Fixing faulty entries does not work fully anymore for multiline entries. Those do show up in my history after editing the former part. That does not have to block this PR though, since it's a nice to have.
interesting, I cannot replicate the issue (we also have a specific test for this).
What I am doing to test the behavior is to paste this
let lineWithMistake = `I have some
problem with` my syntax'
and then fixing it editing the history, and it is working just fine. What are you typing to make the functionality break?
interesting, I cannot replicate the issue (we also have a specific test for this). What I am doing to test the behavior is to paste this
I just had another look and it and it is actually working! I created a ReferenceError, not a SyntaxError. We could probably handle it identically but that is something for another PR as further improvement :)
CI: https://ci.nodejs.org/job/node-test-pull-request/66521/
CI: https://ci.nodejs.org/job/node-test-pull-request/66548/
CI: https://ci.nodejs.org/job/node-test-pull-request/66551/
CI: https://ci.nodejs.org/job/node-test-pull-request/66556/
CI: https://ci.nodejs.org/job/node-test-pull-request/66562/
CI: https://ci.nodejs.org/job/node-test-pull-request/66567/
CI: https://ci.nodejs.org/job/node-test-pull-request/66590/
Commit Queue failed
- Loading data for nodejs/node/pull/58003 ✔ Done loading data for nodejs/node/pull/58003 ----------------------------------- PR info ------------------------------------ Title repl: add possibility to edit multiline commands while adding them (#58003) ⚠ Could not retrieve the email or name of the PR author's from user's GitHub profile! Branch puskin:repl-multiline-refactor-and-while-typing -> nodejs:main Labels readline, repl, author ready, needs-ci Commits 2 - repl: add possibility to edit multiline commands while adding them - repl: add proper vertical cursor movements Committers 1 - Giovanni <[email protected]> PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Pietro Marchini <[email protected]> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Pietro Marchini <[email protected]> -------------------------------------------------------------------------------- ℹ This PR was created on Thu, 24 Apr 2025 12:10:53 GMT ✔ Approvals: 2 ✔ - Ruben Bridgewater (@BridgeAR) (TSC): https://github.com/nodejs/node/pull/58003#pullrequestreview-2812512679 ✔ - Pietro Marchini (@pmarchini): https://github.com/nodejs/node/pull/58003#pullrequestreview-2813299994 ✔ Last GitHub CI successful ℹ Last Full PR CI on 2025-05-04T17:35:22Z: https://ci.nodejs.org/job/node-test-pull-request/66590/ - Querying data for job/node-test-pull-request/66590/ ✔ Last Jenkins CI successful -------------------------------------------------------------------------------- ✔ No git cherry-pick in progress ✔ No git am in progress ✔ No git rebase in progress -------------------------------------------------------------------------------- - Bringing origin/main up to date... From https://github.com/nodejs/node * branch main -> FETCH_HEAD ✔ origin/main is now up-to-date - Downloading patch for 58003 From https://github.com/nodejs/node * branch refs/pull/58003/merge -> FETCH_HEAD ✔ Fetched commits as 5fb879c4584c..1030ce5cbc8a -------------------------------------------------------------------------------- [main 745059a9c5] repl: add possibility to edit multiline commands while adding them Author: Giovanni <[email protected]> Date: Wed Apr 23 15:05:56 2025 +0200 7 files changed, 506 insertions(+), 53 deletions(-) create mode 100644 test/parallel/test-repl-multiline-navigation-while-adding.js [main 48af18f664] repl: add proper vertical cursor movements Author: Giovanni <[email protected]> Date: Thu May 1 10:20:17 2025 +0200 3 files changed, 121 insertions(+), 38 deletions(-) ✔ Patches applied There are 2 commits in the PR. Attempting autorebase. Rebasing (2/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- repl: add possibility to edit multiline commands while adding themhttps://github.com/nodejs/node/actions/runs/14823896908PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
[detached HEAD 62eef37ac7] repl: add possibility to edit multiline commands while adding them Author: Giovanni <[email protected]> Date: Wed Apr 23 15:05:56 2025 +0200 7 files changed, 506 insertions(+), 53 deletions(-) create mode 100644 test/parallel/test-repl-multiline-navigation-while-adding.js Rebasing (3/4) Rebasing (4/4) Executing: git node land --amend --yes --------------------------------- New Message ---------------------------------- repl: add proper vertical cursor movements
PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Pietro Marchini <[email protected]>
[detached HEAD 7b279215aa] repl: add proper vertical cursor movements Author: Giovanni <[email protected]> Date: Thu May 1 10:20:17 2025 +0200 3 files changed, 121 insertions(+), 38 deletions(-) Successfully rebased and updated refs/heads/main.
ℹ Add
commit-queue-squashlabel to land the PR as one commit, orcommit-queue-rebaseto land as separate commits.
Landed in 5fb879c4584cc98889f4424cb60e5f37eb1ea4e7...995ad2b05303ab75e89a58ffcd69f987c2c459d6
This does not land cleanly on v22.x-staging, and would require a manual backport PR if we want it on the 22.x line.