Experimental support for EditContext

Chrome has started shipping edit context, a feature that allows JavaScript to intercept editing actions, including composition-based ones, in a way that isn’t as problematic as the old ‘just see how the DOM changes and hope for the best’ approach. Mozilla is considering the proposal but hasn’t put out a position yet. Apple is responding with deafening silence as usual.

I’m generally a bit wary of Blink-only APIs, but since this may help tame the endless mess of virtual keyboard behavior on Andoid, I built a proof-of-concept implementation that uses this feature, when available, to capture text input. The interface was surprisingly pleasant to use, and fits into CodeMirror rather well. My implementation is in this branch, and available as @codemirror/view 6.26.4-edit-context on npm (under a separate tag).

I would appreciate help testing this. I’m sure there will be new bugs, both in my integration and in Chrome itself (I already ran into a rather bad one in Chrome), but those can hopefully be found and worked out in the near future. Once I’m more confident this is solid, I’ll move it to the main branch, possibly, depending on how solid, behind an option.

6 Likes

This is very exciting!

Would you be open to providing an option for this now, rather than later? It’s fine if it is still in its own special branch. We want to test this at Replit but we’d like to be able to restrict it to just our opt-in beta testers. It would also let us do a semi-graceful fallback if we detect errors.

I’ve published a 6.26.4-edit-context.1 that allows you do EditorView.EDIT_CONTEXT = false to disable use of edit context. This will not be a stable feature, just a kludge that exists as long as this is experimental.

1 Like

Were you able to do any testing on this? Any feedback so far?

@codemirror/view 6.28.0 ships with EditContext support. It would have been nice to get some more testing feedback, but I guess we’re now going to test in production.

2 Likes

Bug #1392 strongly suggests no one did any real testing with this. I’ve disabled EditContext use by default in 6.28.1 again until I work those out.

@marijn

  • I have been using codemirror in my day job, and I was stuck by this change for 2 days.
  • The problem is when I try to rename a file outside of codemirror, codemirror stealed the keyboard input.
    • I have debugged this issue for a long time, I attached event listeners to the rename input , keydown/keyup fires, but beforeinput/input not fired, because codemirror stealed the keyboard input
    • my current solution is to downgrade codemirror to v6.28.1.
    • :question: is there an option to enable/disable EditorContext manually?

It’s unclear what this means.

Yes, it’s described four messages up in the thread you replied to.