Skip to content

fix: trigger select-all via CDP commands field#600

Open
myabc wants to merge 1 commit into
rubycdp:mainfrom
myabc:fix/keyboard-modifier-accelerator
Open

fix: trigger select-all via CDP commands field#600
myabc wants to merge 1 commit into
rubycdp:mainfrom
myabc:fix/keyboard-modifier-accelerator

Conversation

@myabc

@myabc myabc commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Ctrl/Cmd+A does not select text when driven through Ferrum::Node#type / Ferrum::Keyboard. Selecting-then-replacing content in an <input> or a contenteditable is impossible, so callers resort to workarounds. Ferrum's own specs sidestep it — the delete_all helper in spec/node_spec.rb selects via Shift+modifier+Right caret movement rather than Ctrl+A, which only works for single-word content.

Root cause

Synthetic key events dispatched via Input.dispatchKeyEvent do not trigger the browser's editing accelerators. This holds regardless of text presence or keyDown/rawKeyDown type — verified by probing a live browser: no key-event variant of Ctrl/Cmd+A produces a selection.

The reliable mechanism is the CDP commands field on the key event: passing commands: ["selectAll"] makes Chrome run the editing command. This is how Playwright and Puppeteer implement editing shortcuts.

Fix

When a chord matches the platform select-all accelerator (Cmd on macOS, Ctrl elsewhere), name the editing command via commands. Existing text/modifiers handling is untouched — only an extra field is added for the matching chord, so normal typing and all existing modifier behaviour are unaffected.

The editing_command helper is scoped to select-all for now (the common need) and excludes Shift, but is written to extend to further commands.

Testing

New #type specs in spec/node_spec.rb cover a contenteditable (#filled_div) and an <input> (#filled_input): type([mod, "a"], :backspace) clears the field. The full #type context stays green (44 examples).

Real-world beneficiaries

  • capybara_accessible_selectors — clearing a rich-text contenteditable currently needs a driver-specific backspace loop.
  • OpenProject's Capybara helpersclear_input_field_contents does a manual right+backspace dance on inputs (commented "Ferrum is yet support fill_options…"); collapses to node.type([:control, "a"], :backspace) once the accelerator works.

Copilot AI review requested due to automatic review settings July 9, 2026 12:36

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR ensures Ferrum::Node#type triggers the browser’s native “select all” shortcut (Ctrl/Cmd+A) by emitting the appropriate CDP commands field, enabling reliable select-and-replace behavior in inputs and contenteditables.

Changes:

  • Add keyboard normalization logic to map the platform accelerator + A chord to the CDP selectAll editing command.
  • Add specs covering select-all then clear for both an <input> and a contenteditable <div>.
  • Document the fix in the changelog.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
spec/node_spec.rb Adds regression tests verifying select-all then backspace clears input/contenteditable.
lib/ferrum/keyboard.rb Adds mapping from accelerator+A to CDP commands: ["selectAll"] during key normalization.
CHANGELOG.md Documents the select-all shortcut fix for Node#type / Keyboard.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/ferrum/keyboard.rb
Synthetic key events from Input.dispatchKeyEvent do not fire the
browser's editing accelerators, so Ctrl/Cmd+A never selects text in an
input or contenteditable. Name the editing command explicitly via the
CDP `commands` field when a chord matches the platform select-all
accelerator (Cmd on macOS, Ctrl elsewhere).
@myabc myabc force-pushed the fix/keyboard-modifier-accelerator branch from 4a431ec to aa6e300 Compare July 9, 2026 13:04
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.

2 participants