Skip to content

dom: fix macOS text input navigation and clipboard keybindings - #895

Open
GoCoder7 wants to merge 2 commits into
DioxusLabs:mainfrom
techton7:fix/macos-text-input-shortcuts
Open

GoCoder7 wants to merge 2 commits into
DioxusLabs:mainfrom
techton7:fix/macos-text-input-shortcuts

Conversation

@GoCoder7

@GoCoder7 GoCoder7 commented Sep 14, 2026

Copy link
Copy Markdown

Fixes #894.

Summary

This PR addresses several macOS keyboard navigation, shortcut, and clipboard issues in blitz-dom text inputs by adopting the pattern used in VS Code and Zed's editor architecture:

  1. Prevent 2-character jumping on plain arrow keys:

    • On macOS, winit emits both AppleStandardKeyBinding and raw KeyPress.
    • In apply_keypress_event, plain/Option navigation keys are left to AppleStandardKeyBinding so that AppKit can handle them natively (moveLeft:, moveWordLeft:) without duplicate execution.
  2. Support macOS Cmd + Arrow navigation and Cmd + Backspace:

    • AppKit's interpretKeyEvents: treats Cmd keys as application commands and does not emit standard text selectors for them.
    • Handled Cmd + Left/Right (move to line start/end), Cmd + Up/Down (move to document start/end), their Shift selection variants, and Cmd + Backspace (delete to line start) directly in apply_keypress_event.
  3. Support clipboard operations in AppleStandardKeyBinding:

    • Added match arms for "copy:", "cut:", and "paste:" in apply_apple_standard_keybinding.
    • Prevented spurious Input events when performing copy.
  4. Fix selector typo:

    • Fixed typo in "moveToEndOfDocumentAndModifySelection:" calling driver.move_to_text_end() instead of driver.select_to_text_end().
  5. Physical key (Code) mapping for action shortcuts across non-Latin keyboard layouts:

    • Previously, shortcuts were matched only against Key::Character("a" | "c" | "v" | "x"). On non-Latin keyboard layouts (e.g. Korean 2-Set where physical KeyC generates ), shortcuts failed completely.
    • Introduced action_key helper in util.rs to normalize action keystrokes (Cmd on macOS, Ctrl on others) by prioritizing physical key codes (Code::KeyA, KeyC, KeyV, KeyX, KeyZ) with character fallback.
    • Refactored shortcut dispatching in both TextInputData::apply_keypress_event and handle_key_or_input_event using a concise match action_key(&event) pattern.

Testing

  • cargo fmt --all --check: Passed.
  • cargo clippy -p blitz-dom -- -D warnings: Passed (0 warnings).
  • cargo test -p blitz-dom: 56/56 unit tests passed.
  • Tested manually on macOS with wgpu_texture text input across all combinations:
    • Plain arrows (1 character)
    • Option + Arrow (word jump)
    • Cmd + Arrow (line start/end, document start/end)
    • Shift modifier combinations for all the above (selection)
    • Cmd + Backspace (delete to line start)
    • Cmd + C / Cmd + V / Cmd + X / Cmd + A on both English and non-Latin (Korean) layouts

WPT results

No changes in test results compared to main.

Generated by the WPT workflow.

- Prevent duplicate cursor movement by letting AppleStandardKeyBinding handle plain and Option arrow keys on macOS
- Implement macOS Cmd+Arrow navigation (move/select to line start/end, document start/end) and Cmd+Backspace (delete to line start)
- Add missing copy:, cut:, paste: handlers in apply_apple_standard_keybinding and prevent spurious Input event on copy
- Fix typo in moveToEndOfDocumentAndModifySelection: selector
…lize key resolution

- Add action_key helper in util.rs to prioritize physical key codes over layout-specific logical characters
- Enable Cmd/Ctrl + A, C, V, X shortcuts on non-Latin and Korean keyboard layouts
- Clean up shortcut matching with concise match pattern in TextInputData::apply_keypress_event and handle_key_or_input_event
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.

macOS text input: cursor jumps 2 characters, Cmd navigation and clipboard actions not working

1 participant