Skip to content

Conversation

@pashaish
Copy link

Summary

This PR refactors keyboard event handling in text editor and input components to use physical key codes instead of logical keys, improving support for different keyboard layouts and international users.

Changes Made

Core Changes

  • Text Editor (text_editor.rs):

    • Added physical_key field to KeyPress struct
    • Migrated keyboard shortcuts from keyboard::Key matching to Physical::Code matching
    • Updated key bindings for common shortcuts (Ctrl+C, Ctrl+X, Ctrl+V, Ctrl+A, etc.)
  • Text Input (text_input.rs):

    • Updated keyboard event handling to use physical_key instead of key
    • Refactored copy, cut, paste, and select-all shortcuts to use physical key codes
  • Editor Example (examples/editor/src/main.rs):

    • Updated custom key binding for save functionality (Ctrl+S) to use physical key codes
    • Added necessary imports for Code and Physical

Benefits

  • Better International Support: Physical key codes work consistently across different keyboard layouts (QWERTY, AZERTY, QWERTZ, etc.)
  • More Reliable Shortcuts: Shortcuts now work based on physical key position rather than the character produced
  • Consistent UX: Users get the expected behavior regardless of their system keyboard layout

Technical Details

  • Replaces pattern matching on keyboard::Key::Character("c") with Physical::Code(Code::KeyC)
  • Maintains backward compatibility by keeping existing key and text fields in events

Testing

  • Verified that all existing keyboard shortcuts continue to work as expected
  • Tested with different keyboard layouts to ensure consistent behavior

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