fix: trigger select-all via CDP commands field#600
Open
myabc wants to merge 1 commit into
Open
Conversation
5 tasks
There was a problem hiding this comment.
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 +
Achord to the CDPselectAllediting 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.
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).
4a431ec to
aa6e300
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Ctrl/Cmd+Adoes not select text when driven throughFerrum::Node#type/Ferrum::Keyboard. Selecting-then-replacing content in an<input>or acontenteditableis impossible, so callers resort to workarounds. Ferrum's own specs sidestep it — thedelete_allhelper inspec/node_spec.rbselects viaShift+modifier+Rightcaret movement rather thanCtrl+A, which only works for single-word content.Root cause
Synthetic key events dispatched via
Input.dispatchKeyEventdo not trigger the browser's editing accelerators. This holds regardless oftextpresence orkeyDown/rawKeyDowntype — verified by probing a live browser: no key-event variant ofCtrl/Cmd+Aproduces a selection.The reliable mechanism is the CDP
commandsfield on the key event: passingcommands: ["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 (
Cmdon macOS,Ctrlelsewhere), name the editing command viacommands. Existingtext/modifiershandling is untouched — only an extra field is added for the matching chord, so normal typing and all existing modifier behaviour are unaffected.The
editing_commandhelper is scoped to select-all for now (the common need) and excludesShift, but is written to extend to further commands.Testing
New
#typespecs inspec/node_spec.rbcover acontenteditable(#filled_div) and an<input>(#filled_input):type([mod, "a"], :backspace)clears the field. The full#typecontext stays green (44 examples).Real-world beneficiaries
contenteditablecurrently needs a driver-specific backspace loop.clear_input_field_contentsdoes a manual right+backspace dance on inputs (commented "Ferrum is yet supportfill_options…"); collapses tonode.type([:control, "a"], :backspace)once the accelerator works.