Skip to content

fix(keyboard): type "\n" in a string as Enter - #730

Merged
route merged 1 commit into
mainfrom
fix/keyboard-newline
Nov 24, 2026
Merged

route merged 1 commit into
mainfrom
fix/keyboard-newline

Conversation

@route

@route route commented Nov 24, 2026

Copy link
Copy Markdown
Member

keyboard.type("a\nb") and node.type("a\nb") typed "ab": the newline was dropped, while "\r" and :enter worked.

The String branch of normalize_keys looks the character up in keyboard.json and then merges text: char. The keymap has "\n" as the Enter key with text: "\r", but the merged "\n" wins, so Chrome got a keypress with text: "\n" and inserted nothing. "\n" is the only single-character key whose text differs from the character.

  • The String branch uses the keymap's text when it has one, with or without modifiers.
  • New #type spec types "a\nb" into a textarea. It fails without the change ("ab").
  • CHANGELOG line under Fixed.

Found while making Cuprite fill text fields with real key presses (rubycdp/cuprite#377), which works around it by sending "\r".

normalize_keys merged text: char over the keymap entry, so "\n" was sent with text "\n" instead of the Enter key's "\r", and Chrome inserted
nothing. It now uses the keymap's text when there is one; "\n" is the only single-character key where it differs.
@route
route merged commit 7ea932c into main Nov 24, 2026
11 of 12 checks passed
@route
route deleted the fix/keyboard-newline branch November 24, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant