Skip to content
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

feat(minttea): supporting ctrl-key modifiers #45

Merged
merged 3 commits into from
Mar 27, 2024
Merged

Conversation

wllfaria
Copy link
Contributor

This patch aims to add support for Ctrl modifiers on keys.

This is a breaking change on the current interface of how key events are disposed to users.

NOTE: the amount of changes is due to re-creating all the examples and having to account for the change on the Key type.

I can either continue to add support for other modifiers here or in other Pull requests. Either way works for me.

Relates to #3

minttea/event.ml Outdated
@@ -1,5 +1,8 @@
open Riot

type modifier = Ctrl
type key_event = { key : string; modifier : modifier option }
Copy link
Owner

@leostera leostera Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion. Could we move the modifier up to the KeyDown constructor?

type t =
 | KeyDown of key * modifier

I think this would allow you to pass in modifier for the special keys too, while keeping all the pattern matching ergonomic:

let update t e = 
  match e with
  | KeyDown (Key "h" | Left, Ctrl) -> prev_page t
  | KeyDown (Key "l" | Right, None) -> next_page t

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't think of this, I think this is way better and more ergonomic, will add these changes

minttea/event.ml Outdated
@@ -1,5 +1,8 @@
open Riot

type modifier = Ctrl
type key_event = { key : string; modifier : modifier option }
Copy link
Owner

@leostera leostera Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question. Another thought is that to avoid the (Some Ctrl) wrapper when we want Ctrl we could make the modifier type just include a "no-modifier" variant like No_modifier:

type modifier = | No_modifier | Ctrl

Stuffing this type with combinations would also make it easier to check for Ctrl + Shift by just using CtrlShift instead of trying to have a set / list.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is really good, I just added option as it made sense that no modifiers could just be None, but either way works fine. But I do enjoy not have Some/Nones. To me this suggestion is great

@leostera
Copy link
Owner

Hi @wllfaria, thanks for the PR! ✨ – left you some thought around the DX and how to keep extending the modifiers while allowing them on all possible keys (including the ones we special cased).

Let me know what you think :)

@wllfaria
Copy link
Contributor Author

I've added updates addressing your considerations. Let me know if you think something should be different.

Copy link
Owner

@leostera leostera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@leostera
Copy link
Owner

@wllfaria changes look good to me! Thanks again for the PR 🙏🏼

There's one thing with some of the gifs (eg. the input field + cursor, list demo gif) where the behavior looks slightly different. I think it could just be an issue with the recording, but if you could have a look that'd be super appreciated.

Both of those gifs show a "j" right on the last interaction that I don't think was there before, but I can't see that anywhere in the code.

Any thoughts? Otherwise we can merge this as is and if you find the problem we can open an issue and fix that separately.

@leostera leostera mentioned this pull request Mar 26, 2024
10 tasks
@wllfaria
Copy link
Contributor Author

That was a good catch from you, turned out that was a issue with how enter was getting parsed. Enter is sent as \n, and this matches against \x01-\x1a, I added a special case for \n before the matching and this should be fixed now.

I think it would be good to maybe implement testing for this, so we can guarantee that further changes don't break past implementations, I can discuss this further here or in discord if you want.

@leostera leostera merged commit 9445c4e into leostera:main Mar 27, 2024
@leostera
Copy link
Owner

This looks great now! 🙌🏼 Could you make a new issue to discuss this testing? The discord is also good but it'd be nice to have a reference back to this. We can of course discuss first in discord and then make an issue too :) up to you!

Again, thanks for the PR ✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants