-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
repl: add possibility to edit multiline commands while adding them #58003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: add possibility to edit multiline commands while adding them #58003
Conversation
7353efd
to
9aca5ed
Compare
Codecov ReportAttention: Patch coverage is
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
🚀 New features to boost your workflow:
|
fe64915
to
4088f89
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great work and almost LGTM! I would just like to have some more tests for positions pressing enter before the end.
One behavior that I noticed that could be improved after landing is the cursor positioning while moving upwards. Imagine line 12\n1\n123 UP, UP. The cursor should actually be at the end of line 1 (12) instead of in the middle. It is a typical behavior when moving the cursor up, so keeping that would be nice.
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.
const repl = require('internal/repl'); | ||
const stream = require('stream'); | ||
|
||
class ActionStream extends stream.Stream { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We repeat this in pretty much all REPL tests. Maybe it's time for a helper method? :)
I am a bit uncertain where to place that though. Mostly common is a place for helpers but this is very specific for the REPL, so maybe somewhere else.
This is not blocking.
interesting, I cannot replicate the issue (we also have a specific test for this).
and then fixing it editing the history, and it is working just fine. What are you typing to make the functionality break? |
4088f89
to
7b3c67f
Compare
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 :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with my last comment addressed. This is really good work!
7b3c67f
to
ff4639e
Compare
210b0da
to
1030ce5
Compare
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 <github@puskin.it> PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> ------------------------------ Generated metadata ------------------------------ PR-URL: https://github.com/nodejs/node/pull/58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com> -------------------------------------------------------------------------------- ℹ 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 <github@puskin.it> 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 <github@puskin.it> 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/14823896908 |
Landed in 5fb879c...995ad2b |
PR-URL: #58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
PR-URL: #58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
PR-URL: #58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
PR-URL: #58003 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Pietro Marchini <pietro.marchini94@gmail.com>
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. |
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
Enter
behaves as usual:Limitations:
}
or`
).Shift + Enter
. I’ve left a TODO to revisit this and debug further.EDIT
Implemented vertical cursor movement as well