-
Notifications
You must be signed in to change notification settings - Fork 30
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
Improve Key API and keys event handling #556
Conversation
Question: Would it be nice from the On the other hand it would be at least one call on top and also would probably need some sort of filter to only apply the lowercase to one length strings (as the predefined all starts with upper case!) |
After dicussing the issue with lower- vs upper-case keys, we have decided to look for a rational implementation that will detect all none special keys and transform them to lower-cases. This way the API is much more pleasent as it would make no difference if one writes |
- add some convenience methods to improve the event handling for `KeyboardEvent`s: ``keys()`` which accepts one, arbitrary or a set of `Key`s which should be handled. All events from other keys will be dropped, so that one can prevent default behaviour or stop bubbling explicitly only for the handled keys - returns a pair of the key and the accompanied event, so that calling `stopPropagation` or accessing other properties of the event is still possible for the client.
- simplify predefined keys to be just string constants. This reduces object construction overhead for static keys including missing event. - reshape `Key` class to expose the relevant fields for a key as properties combined with the corresponding `KeyboardEvent` in order to process the event further without loosing those informations. - add `keys()` functions for `WindowListener` too - mark `key()` function as deprecated as there is really no use case for this! (Grabbing a key without filtering just makes no sense at all!) - adapt some components to new API and `keys`-functions. - adapt test cases
- add concept of "extra keys" with own interface. This enables combination with other extra keys and "real" keys but prevents combination of real keys, which would be meaningless: ```kotlin Keys.Control + "K" Key("K", ctrl = true) Keys.Control + Keys.Shift + "F" Key("F") + Keys.Alt // won't compile Key("F") + Key("P") ``` - offer extra keys as predefined objects in ``Keys``-object - rework `keys`-functions to work with new Key-API - deprecate some key event based special interest functions in favour of new `keys` functions, which leverages the heavy work already in a generic way
9e61485
to
a060cad
Compare
a060cad
to
ea11428
Compare
- ctor of `Key` now automatically converts single letter key names to lower-case in order to be compliant to keyboard-events key property, which is always lower-case for single letter keys. - add unit tests - adapt documentation
This PR improves the whole key event handling API by the following aspects:
Key
-class based upon a new concept ofModifier
-interface, which enables constructing nice key shortcut combinations like "Strg + K" or "Shift + Alt + F" or alike.KeyboardEvent
s:keys()
Keys
-object with predefined common keys likeTab
,Enter
but also the modifier keys likeAlt
,Shift
,Meta
andControl
keys
functions, which does the heavy work without being too specialized.The new key API allows easily defining combinations of keys with modifier keys, constructing those from a
KeyboardEvent
and prevents meaningless combinations of "real" keys:As most of the time you will use keys within the handling of some
KeyboardEvent
, there are some new methods for leveraging some common work by the framework. Thosekeys
-methods variants accept one, arbitrary or a set ofKey
s which should be handled. All events from other keys will be ignored, so that one can prevent default behaviour or stop bubbling explicitly only for the handled keys. The functions return a pair of the key and the corresponding event, so that callingstopPropagation
or accessing other properties of the event is still possible for the client.Example usage: