-
Notifications
You must be signed in to change notification settings - Fork 27
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
Force keyboard events to stop propagating #61
Conversation
Thanks for the PR and opening the issue. The intent is definitely that keyboard events should be captured. When I tried your example in #60 with the current release and Chrome on a Mac, though, it looks like events are being captured. What browsers/ipyevents version are you using? |
Hm, that is odd! I'm testing on Windows 10, build 1909, with Chrome 86.0.4240.183 and ipyevents 0.8.1/1.8.1. One thing I will note that I forgot to in the original issue is that this only occurs when the key is held, and the repeat events are firing. I did also just test in Chrome on a Mac, and I didn't see the issue, so there might be something different in how MacOS and Windows handle repeating key events. |
That is really useful to know -- I don't have a windows machine to test on at the moment. I don't see how this would do any harm on other platforms, nor do I see a case where throttling + letting the event propagate is desirable so it seems ok to merge. I don't understand why this isn't working: https://github.com/mwcraig/ipyevents/blob/master/src/events.ts#L268 Though, tbh, much about DOM events mystifies me. |
Without having looked into the way Chrome handles events, or the underscore library too much, my guess is that the throttling prevents the code stopping event propagation from running, and if the browser/library queues the delayed handler asynchronously then the handlers which should be preempted run before the delayed handler, but there's a lot going on that's still a mystery to me too. |
Can you please check whether throttling still works for you for no_rate_box = Label("No rate limit (all scroll events passed)", layout={'border': '2px solid red', 'width': '100%'})
throttle_box = Label("Throttle (no more than 0.5 event per sec)", layout=no_rate_box.layout)
debounce_box = Label("Debounce (wait 0.5 sec between scrolls)", layout=no_rate_box.layout)
event_no_rate = Event(source=no_rate_box, watched_events=['wheel'])
# If you omit throttle_or_debounce it defaults to throttle
event_throttle = Event(source=throttle_box, watched_events=['wheel'], wait=500)
event_debounce = Event(source=debounce_box, watched_events=['wheel'], wait=500, throttle_or_debounce='debounce')
wheel_info = HTML("Waiting for a scroll...")
def update_display(event):
lines = [
'timeStamp: {}'.format(event['timeStamp']),
'deltaY: {}'.format(event['deltaY'])
]
content = '<br>'.join(lines)
wheel_info.value = content
event_no_rate.on_dom_event(update_display)
event_throttle.on_dom_event(update_display)
event_debounce.on_dom_event(update_display)
instructions = HTML("Mouse over each box then scroll to see response")
VBox([instructions, HBox([no_rate_box, throttle_box, debounce_box], layout={'width': '100%'}), wheel_info]) |
On Windows, it does appear to still work for me, in what manner is it not working? (I can test it again on Mac, but that machine's a bit inconvenient for me) |
It isn't throttling for me. I'll dig into the websocket traffic today and see if I can track down why. |
6e2b71f
to
cc40b7c
Compare
May resolve #60, if that issue describes unintended behaviour.