Skip to content

readline: align delete-word-right span with word-right - #65180

Open
arhxam wants to merge 1 commit into
nodejs:mainfrom
arhxam:readline-delete-word-right
Open

readline: align delete-word-right span with word-right#65180
arhxam wants to merge 1 commit into
nodejs:mainfrom
arhxam:readline-delete-word-right

Conversation

@arhxam

@arhxam arhxam commented Aug 10, 2026

Copy link
Copy Markdown

Description

[kDeleteWordRight]() in lib/internal/readline/interface.js matched the
text after the cursor with /^(?:\s+|\W+|\w+)\s*/. Its three sibling
word-motion handlers all use [^\w\s]+ (a run of punctuation, excluding
whitespace) for the symbol-run alternative:

  • [kWordLeft]/^\s*(?:[^\w\s]+|\w+)?/
  • [kWordRight]/^(?:\s+|[^\w\s]+|\w+)\s*/
  • [kDeleteWordLeft]/^\s*(?:[^\w\s]+|\w+)?/

\W also matches whitespace, so delete-word-right (Meta+d,
Ctrl+Delete, Meta+Delete) removes a different span
than word-right (Meta+f, Ctrl+Right) traverses
whenever the text ahead of the cursor is punctuation, then whitespace,
then more punctuation.

Reproduction (built from this branch's parent, terminal: true):

line "-> => x", cursor at column 0
  word-right         -> advances over "-> "     (cursor at 3)
  delete-word-right  -> deletes "-> => ", leaving "x"   (should leave "=> x")

Forward-word and kill-word are expected to cover the same span (as they
do in bash / GNU readline / emacs), and the other three handlers already
agree with each other. This aligns [kDeleteWordRight] with
[kWordRight] by using [^\w\s]+.

Verification

  • Reproduced on a from-source build of main; the new regression test
    fails on the unpatched source (actual: 'x', expected: '=> x') and
    passes with the fix.
  • Regression tests added to test-readline-interface.js and
    test-readline-promises-interface.js (covering all three key bindings).
  • Full test/parallel/test-readline*.js suite (21 files): all pass. The
    existing word-only cases are unaffected (both regexes agree on \w).

`[kDeleteWordRight]()` matched the text after the cursor with
`/^(?:\s+|\W+|\w+)\s*/`, but its three sibling word-motion handlers
(`kWordLeft`, `kWordRight`, `kDeleteWordLeft`) use `[^\w\s]+` for the
symbol run. `\W` also matches whitespace, so delete-word-right (Meta+d
or Ctrl+Delete) removed a different span than word-right (Meta+f)
traverses whenever the text ahead was punctuation, whitespace, then more
punctuation: for `-> => x` at column 0, word-right advances over `-> `
while delete-word-right deleted `-> => `.

Use `[^\w\s]+` so the pattern is identical to `kWordRight` and the two
operations always cover the same span.

Signed-off-by: Arham Wani <arhamwani765@gmail.com>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module. labels Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. readline Issues and PRs related to the built-in readline module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants