Skip to content

feat: parse key symbols and os-specific key names in KeyBinding.from_str - #293

Open
tlambert03 wants to merge 1 commit into
pyapp-kit:mainfrom
tlambert03:feat/parse-key-symbols
Open

tlambert03 wants to merge 1 commit into
pyapp-kit:mainfrom
tlambert03:feat/parse-key-symbols

Conversation

@tlambert03

Copy link
Copy Markdown
Member

closes #214

KeyBinding.to_text(use_symbols=True) produces strings that from_str couldn't parse back (e.g. from_str("Ctrl+↵") silently gave Ctrl+ with an unknown key, and mac-style ⌘⇧↵ didn't parse at all). This adds the symbols/names from os_symbol/os_name to the string->KeyCode map, and lets modifier symbols omit the +/- separator (as long as a key follows), so to_text output round-trips for +/- joins on all platforms, and for mac symbols with no joinchar.

(fwiw, this is the reverse of what napari's Shortcut.parse_platform does by hand)

@codecov

codecov Bot commented Nov 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.49%. Comparing base (939ee7a) to head (f8f4b78).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #293   +/-   ##
=======================================
  Coverage   99.49%   99.49%           
=======================================
  Files          31       31           
  Lines        1970     1973    +3     
=======================================
+ Hits         1960     1963    +3     
  Misses         10       10           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tlambert03

Copy link
Copy Markdown
Member Author

cc @jni, @TimMonko, @Czaki ... i believe that after this merges, if you bump your app-model pinning, KeyBinding.from_str should be able to replace napari's Shortcut.parse_platform (here)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Enable parsing symbols and os-specific string representations of keys (besides modifiers)

1 participant