-
Notifications
You must be signed in to change notification settings - Fork 33
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
events triggered by calls into CodeMirror should be delivered asynchronously #70
Comments
@skybrian, is this something you could create a PR for? |
Maybe, but I'm not sure about the consequences. I think a one line change at [1] to remove "sync: true" would fix this issue. However, I don't know if that would affect performance or timing in a bad way for other users of the CodeMirror package. Also, it looks like you added that line as part of a large change to upgrade to CodeMirror 5.0. Do you remember why you added it? (It's not a big priority for me as I've already worked around it, but I thought I'd report it.) [1] https://github.com/google/codemirror.dart/blob/master/lib/src/js_utils.dart#L70 |
Unfortunately I don't remember what motivated that change. I have in the past needed to make async user events sync in order to make sure I'm the one who handles the event (and can then cancel it), or because the browser only allows some actions when responding to a user event. Not sure if either was the case here. |
A more conservative solution might be to set a flag when entering codemirror, and create a microtask in the callback if the flag is set. If the flag isn't set then the event was triggered from outside Dart and microtask is needed. But since I've already worked around it, I think the easiest thing for now is just to leave the bug open. |
More subtlety to think about: If some CodeMirror events are delivered via a microtask and others are not, they would get delivered out of order. Also, in a regular HTML event handler, events are delivered synchronously, allowing you to call event.preventDefault(). I don't know if it's possible to handle an HTML event that is also delivered to CodeMirror, but if so, a microtask would change the order. An interesting article about this: |
mirror.onEvent("focus", false) returns a stream of events that happens whenever CodeMirror gets focus.
Calling mirror.focus() causes an event to be delivered synchronously (in the middle of the focus call). This isn't normal behavior for a Dart stream; usually events are delivered asynchronously (such as in a microtask).
The text was updated successfully, but these errors were encountered: