Fix press Control+a and other modifier key chords (#980)
The `press` command was not parsing modifier+key chords (e.g. `Control+a`, `Shift+Enter`). It sent the raw string as a single key name, so CDP never applied the modifier — and the `text` field caused the literal character to be inserted instead of triggering the shortcut. Two changes: 1. `actions.rs` — add `parse_key_chord()` to split inputs like `Control+Shift+a` into the base key (`a`) and a CDP modifier bitmask (Alt=1, Ctrl=2, Meta=4, Shift=8), then call `press_key_with_modifiers` instead of `press_key`. 2. `interaction.rs` — suppress the `text` field in `keyDown`/`keyUp` events when Control or Meta modifiers are active, so the browser treats them as command chords rather than text input. Includes unit tests for the chord parser covering plain keys, single modifiers, multi-modifier combos, modifier aliases, and edge cases. Co-authored-by: ctate <366502+ctate@users.noreply.github.com>
This commit is contained in:
@@ -282,7 +282,15 @@ pub async fn press_key_with_modifiers(
|
||||
modifiers: Option<i32>,
|
||||
) -> Result<(), String> {
|
||||
let (key_name, code, key_code) = named_key_info(key);
|
||||
let text = key_text(&key_name);
|
||||
|
||||
// Suppress text insertion when Control (2) or Meta (4) modifiers are active,
|
||||
// since these are command chords (e.g. Ctrl+A = select-all), not text input.
|
||||
let has_command_modifier = modifiers.is_some_and(|m| m & (2 | 4) != 0);
|
||||
let text = if has_command_modifier {
|
||||
None
|
||||
} else {
|
||||
key_text(&key_name)
|
||||
};
|
||||
|
||||
client
|
||||
.send_command_typed::<_, Value>(
|
||||
|
||||
Reference in New Issue
Block a user