File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1390,8 +1390,8 @@ added: REPLACEME
13901390> Stability: 1 - Experimental
13911391
13921392Enable experimental REPL enhancements including inline syntax highlighting,
1393- auto-indentation, and function signature hints. See the
1394- [ REPL] [ ] documentation for details.
1393+ auto-indentation, function signature hints, and block-based history
1394+ navigation. See the [ REPL] [ ] documentation for details.
13951395
13961396### ` --experimental-sea-config `
13971397
Original file line number Diff line number Diff line change @@ -498,6 +498,22 @@ inspector protocol to safely extract function signatures without side
498498effects. Signature hints require the ` preview ` option to be enabled and
499499the inspector to be available.
500500
501+ ### Block-based history navigation
502+
503+ <!-- YAML
504+ added: REPLACEME
505+ -->
506+
507+ > Stability: 1 - Experimental
508+
509+ When the ` --experimental-repl-enhancements ` flag is enabled, pressing the
510+ Up and Down arrow keys navigates between history entries as whole blocks.
511+ Without this flag, pressing Up within a recalled multiline entry first moves
512+ the cursor through the entry's lines before advancing to the previous history
513+ entry. With the flag enabled, Up/Down always jump directly to the
514+ previous/next history entry, making it easy to recall multiline functions
515+ and code blocks.
516+
501517## Class: ` REPLServer `
502518
503519<!-- YAML
Original file line number Diff line number Diff line change @@ -780,8 +780,8 @@ Enable experimental support for the QUIC protocol.
780780.
781781.It Fl -experimental-repl-enhancements
782782Enable experimental REPL enhancements including inline syntax highlighting,
783- auto-indentation, and function signature hints. See the
784- REPL documentation for details.
783+ auto-indentation, function signature hints, and block-based history
784+ navigation. See the REPL documentation for details.
785785.
786786.It Fl -experimental-sea-config
787787Use this flag to generate a blob that can be injected into the Node.js
Original file line number Diff line number Diff line change @@ -175,6 +175,8 @@ const {
175175 kMultilinePrompt,
176176 kAddNewLineOnTTY,
177177 kLastCommandErrored,
178+ kHistoryPrev,
179+ kHistoryNext,
178180} = require ( 'internal/readline/interface' ) ;
179181
180182// Lazy-loaded.
@@ -967,7 +969,20 @@ class REPLServer extends Interface {
967969 clearPreview ( key ) ;
968970 clearSignatureHint ( ) ;
969971 if ( ! reverseSearch ( d , key ) ) {
970- ttyWrite ( d , key ) ;
972+ // When enhancements are enabled, Up/Down navigate history in
973+ // blocks rather than moving line-by-line within a recalled
974+ // multiline entry. This makes arrow-key history navigation
975+ // behave like Ctrl-P / Ctrl-N (see issue #48146).
976+ if ( experimentalREPLEnhancements &&
977+ ( key . name === 'up' || key . name === 'down' ) ) {
978+ if ( key . name === 'up' ) {
979+ self [ kHistoryPrev ] ( ) ;
980+ } else {
981+ self [ kHistoryNext ] ( ) ;
982+ }
983+ } else {
984+ ttyWrite ( d , key ) ;
985+ }
971986 const showCompletionPreview = key . name !== 'escape' ;
972987 showPreview ( showCompletionPreview ) ;
973988 // Show signature hint when user types '('.
You can’t perform that action at this time.
0 commit comments