-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Validate the content of binding keys during construction of bindings #1324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate the content of binding keys during construction of bindings #1324
Conversation
…ovide alternative key suggestions when they are not
…s (like ctrl/meta/...) are permitted by using the plus ('+') sign as a separator
…ed regardless of whether a suggested alternative is found
…since it is constructed dynamically
Sometimes I wonder whether doing this is too-precise/too-fragile and whether substring matches are preferable. It seemed useful to do this during development, but perhaps there is a better way
With this someone who has textual[dev] installed can run: $ textual keys and explore which keys make it through their terminal to Textual, and also explore what those keys are called for the purposes of binding (although Textualize#1324 if it makes it in will also be helpful here too).
| if suggested_key: | ||
| msg += f"; try replacing it with '{suggested_key}'" | ||
| raise BindingError(msg) | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering: rather than loop over the keys twice, first to validate and then to actually create the bindings; perhaps do the validation within the binding loop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tricky to say - in generator functions I like to avoid too many sychronization blocks like this, but.. validating state before yielding any/partial output seems like a good idea too, generally.
I'd probably lean towards a cautious approach to begin with (perform the validation separately, and not worry too much about performance/conciseness yet - as long as this isn't a performance bottleneck). Open to other considerations, though.
|
We accept symbols in addition to their spelled out equivalent now. So we don't need this functionality right now. It is a good idea though. In the future, I would like to have something which validated typos in bindings. |
Although some (todo: be more precise?) binding keys may display as-expected when rendered within the application, they aren't matched by the corresponding keypress event keys (for example, pressing
.on the keyboard parses asfull_stop, and won't match a binding for key.).This changeset adds validation for binding keys, and displys a suggested alternative value for invalid entries when possible.
May resolve #101.
Please review the following checklist.