Skip to content

repl: add block-based history navigation#64477

Open
hemanth wants to merge 2 commits into
nodejs:mainfrom
hemanth:repl/block-history-nav
Open

repl: add block-based history navigation#64477
hemanth wants to merge 2 commits into
nodejs:mainfrom
hemanth:repl/block-history-nav

Conversation

@hemanth

@hemanth hemanth commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

When --experimental-repl-enhancements is enabled, the Up and Down arrow keys now navigate between history entries as whole blocks instead of moving line-by-line within a recalled multiline entry.

Problem

When recalling a multiline function from history and pressing Up, the cursor moves within that entry's lines before advancing to the previous history entry. This makes navigating history with multiline entries tedious — you have to press Up multiple times just to get past a single recalled block.

Solution

With --experimental-repl-enhancements enabled, Up/Down always jump directly to the previous/next history entry, matching the behavior of Ctrl-P/Ctrl-N. This makes it easy to recall multiline functions and code blocks with a single keypress.

Implementation

  • Import kHistoryPrev/kHistoryNext symbols from internal/readline/interface
  • Intercept Up/Down in the REPL's _ttyWrite handler when enhancements flag is on
  • Call kHistoryPrev()/kHistoryNext() directly, bypassing the multiline-move-within-entry logic

Note: This PR depends on #64443 which introduces the --experimental-repl-enhancements flag.

Fixes: #48146

Add experimental REPL enhancements behind the
--experimental-repl-enhancements flag:

1. Inline syntax highlighting using the Acorn tokenizer
   to colorize keywords (magenta), strings (green),
   numbers (yellow), booleans/null (yellow), regular
   expressions (red), and comments (gray).

2. Auto-indentation for multiline input based on
   brace/bracket/paren depth, using 2-space indentation.

3. Function signature hints that display parameter lists
   as dimmed text below the input when the user types a
   function call.

All features are off by default and require the CLI flag
to enable. Highlighting is applied at display time only
so cursor positioning and evaluation are unaffected.

Refs: nodejs#48164
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Review requested:

  • @nodejs/config

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Jul 13, 2026
When --experimental-repl-enhancements is enabled, the Up and Down
arrow keys now navigate between history entries as whole blocks
instead of moving line-by-line within a recalled multiline entry.

Previously, recalling a multiline function from history and pressing
Up would move the cursor within that entry's lines before advancing
to the previous history entry. With this change, Up/Down always jump
directly to the previous/next history entry, matching the behavior
of Ctrl-P/Ctrl-N.

Fixes: nodejs#48146
Signed-off-by: hemanth <hemanth.hm@gmail.com>
@hemanth hemanth force-pushed the repl/block-history-nav branch from ffdbb59 to 35cf0f2 Compare July 13, 2026 17:51
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 73.30754% with 138 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.19%. Comparing base (14166a5) to head (35cf0f2).
⚠️ Report is 21 commits behind head on main.

Files with missing lines Patch % Lines
lib/internal/repl/utils.js 70.79% 131 Missing and 1 partial ⚠️
lib/repl.js 90.47% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #64477      +/-   ##
==========================================
- Coverage   90.23%   90.19%   -0.05%     
==========================================
  Files         741      741              
  Lines      241375   242181     +806     
  Branches    45483    45642     +159     
==========================================
+ Hits       217800   218427     +627     
- Misses      15129    15291     +162     
- Partials     8446     8463      +17     
Files with missing lines Coverage Δ
src/node_options.cc 76.65% <100.00%> (-0.08%) ⬇️
src/node_options.h 98.02% <100.00%> (+<0.01%) ⬆️
lib/repl.js 93.86% <90.47%> (-0.15%) ⬇️
lib/internal/repl/utils.js 87.56% <70.79%> (-8.83%) ⬇️

... and 35 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread doc/api/cli.md
Comment on lines +1384 to +1394
### `--experimental-repl-enhancements`

<!-- YAML
added: REPLACEME
-->

> Stability: 1 - Experimental

Enable experimental REPL enhancements including inline syntax highlighting,
auto-indentation, function signature hints, and block-based history
navigation. See the [REPL][] documentation for details.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this be experimental, wouldn't it just be a breaking change, idomatically?

@avivkeller avivkeller added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

repl: history in blocks, rather than lines.

3 participants