Skip to content

Conversation

@jayaddison
Copy link

@jayaddison jayaddison commented Dec 6, 2022

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 as full_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.

  • Docstrings on all new or modified functions / classes
  • Updated documentation
  • Updated CHANGELOG.md (where appropriate)

…ed regardless of whether a suggested alternative is found
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
@jayaddison jayaddison marked this pull request as ready for review December 12, 2022 12:36
davep added a commit to davep/textual that referenced this pull request Dec 16, 2022
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)

Copy link
Contributor

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?

Copy link
Author

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.

@willmcgugan
Copy link
Member

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.

@jayaddison jayaddison deleted the issue/1323/check-binding-key-alnum branch December 29, 2022 12:19
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.

Switching to v0.1.11 Caused a Crash

3 participants