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

Passive event listeners #4292

Closed
viebel opened this issue Oct 9, 2016 · 7 comments
Closed

Passive event listeners #4292

viebel opened this issue Oct 9, 2016 · 7 comments

Comments

@viebel
Copy link

viebel commented Oct 9, 2016

I'd like to have a pasive event listener https://developers.google.com/web/updates/2016/06/passive-event-listeners
to handle an extraKey event.

Is there a way to configure a passive event listener in CodeMirror?

The rationale is that I'm doing heavy computation when the extraKey is triggered and I don't want the page scrolling to be stuck.

@marijnh
Copy link
Member

marijnh commented Oct 9, 2016

Key events aren't fired for scrolling, so I'm not sure how this would help. Doing less heavy computations in your key handlers, or splitting the work up in smaller slices using setTimeout, seems like a more promising approach.

@marijnh marijnh closed this as completed Oct 9, 2016
@viebel
Copy link
Author

viebel commented Oct 10, 2016

Thanks for the tip @marijnh.

I tried to delay the whole computation using setTimeout but it doesn't work inside CodeMirror.

Although it works with a regular textarea.

Here is a jsfiddle for the repro: https://jsfiddle.net/viebel/9f1hojuq/12/

Any help will be much appreciated.

@marijnh
Copy link
Member

marijnh commented Oct 10, 2016

An infinite loop is always going to break your page. That's how JavaScript works -- non-web-worker scripts are run on a single thread and block the page.

@viebel
Copy link
Author

viebel commented Oct 10, 2016

I know. But in some cases, page scroll is not blocked. Take a look at the
jsfiddle with the textarea.

On Mon, Oct 10, 2016, 10:56 Marijn Haverbeke notifications@github.com
wrote:

An infinite loop is always going to break your page. That's how JavaScript
works -- non-web-worker scripts are run on a single thread and block the
page.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4292 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6VPskVI3WI3UgxbCs-ewU6OVJcdKw4ks5qye-_gaJpZM4KR7iR
.

@marijnh
Copy link
Member

marijnh commented Oct 10, 2016

I guess if you don't register an active scroll listener you can still scroll a stuck page. (I'm not sure why, since scroll events only fire after the actual scrolling happens anyway). But CodeMirror needs a scroll listener, so that's just not going to work with CodeMirror. (And your user experience will still be terrible if your script is working for long periods of time, even if scrolling continues to work.)

@viebel
Copy link
Author

viebel commented Oct 10, 2016

My use case is for a blog post with code snippets so the experience would
not so terrible if for 10 seconds the browser is stuck - providing that the
scroll works.

Anyway, why does CodeMirror need a scroll listener?
Is there a hack to disable this scroll listener?

On Mon, 10 Oct 2016 at 11:03 Marijn Haverbeke notifications@github.com
wrote:

I guess if you don't register an active scroll listener you can still
scroll a stuck page. (I'm not sure why, since scroll events only fire after
the actual scrolling happens anyway). But CodeMirror needs a scroll
listener, so that's just not going to work with CodeMirror. (And your user
experience will still be terrible if your script is working for long
periods of time, even if scrolling continues to work.)


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#4292 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AA6VPsQfJgPmQZ1OEabt_zV8msY4-lGoks5qyfFogaJpZM4KR7iR
.

@marijnh
Copy link
Member

marijnh commented Oct 10, 2016

Anyway, why does CodeMirror need a scroll listener?

To keep its viewport in sync with the scroll position, and to keep the gutter in place.

Is there a hack to disable this scroll listener?

No.

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

No branches or pull requests

2 participants