Programmatically Start CompositionEvent with ProseMirror

How would one start a composition event within ProseMirror?

Usually, composition events are started by an IME in the user’s OS. During composition, text-handling by ProseMirror can be skipped by using the view.composing field.

Similar things like autocomplete or slash menu (which insert text into the editor but should ignored by most plugins until the query is complete) could also be wrapped in a composition event. Is there a way to start and end composition events from a ProseMirror plugin?

Write a plugin with props’s handleDOMEvents for handing compositionstart and compositionend events.

No, there is no way to do this, and I don’t think it is the proper solution for what you are trying to do. What kind of text-handling are you trying to suppress? Something like a slash menu is probably best handled by a key binding.

For something like a slash menu, I was thinking a plugin should initialize a composition event while other plugins ignore the in between state.

Reasoning is in a collaborative setting, a slash menu command that appears in one user’s editor e.g. /heading should not appear in another user’s editor until composition end. Another example is an autocomplete emoji menu: intermediate states like :sm:smile: should not be synced only :). I feel like this would be similar to how IME composition sort of behaves?

I think you’re misunderstanding how ProseMirror handles composition – it immediately commits changes to its state as the composition updates, so they will show up in other collaborative peer documents before the composition is finished.

This would depend on collaboration implementation right? It might be possible to pause remote “writes” during composition but allow for local writes to still modify state. (Mentioned but not implemented here: Chinese / japanese input are syncd unexpectedly before compositionend · Issue #81 · yjs/y-prosemirror · GitHub)

Right, you could pause sending of steps when a composition is active, but then no changes would be broadcast in that time. You should be able to implement an additional custom bit of ‘paused’ state that acts the same way, if you control both the code that schedules step broadcasting and the code that makes the change you want to delay sending.