How do I?
In this page we answer a list of commonly asked things
#
How do I watch for changes to the editor?Create a plugin that watches changes to the editor, see exporting data for an example.
#
How do I handle editor's DOM events ?Create a plugin which listens to DOM events as show below:
💡 See Prosemirror.EditorProps for the API.
#
How do I add a keyboard shortcut ?📖 See Keybindings Guide
#
How do I execute a command ?If you are using the vanilla setup, you can get access to view
from the editor instance. For example
In a React setup you can get the view
from the hook useEditorViewContext for components rendered inside the <BangleEditor />
. For components
outside <BangleEditor />
, save the editor
in your applications state management for retrieval and access. Don't forget to clean it up when your editor is destroyed.
view
, state
, dispatch
for a command?#
How do I get access to the See ### How do I execute a command ?
above.
#
How do I get access to Prosemirror schema ?If you are using specs:[ ... ]
notation, switch to using SpecRegistry.
prosemirror-*
module ?#
How do I access You can either npm install them:
or use the ones provided in bangle core which follow the path of @bangle.dev/core/prosemirror/<name_of_module>
:
I recommend the later approach to avoid problems with different versions of Prosemirror existing in your application.
#
How do I change the selection ?First, you will need to figure out whether you want a TextSelection (majority of the cases) or a NodeSelection. Below is an example of setting selection to the end:
#
How do I programmatically update the doc content?This is a pretty heavy question as this requires Prosemirror knowledge of dealing with transactions
. To get started read up on
- Read the Prosemirror guide at least 3 times.
- Browse the source code of some of your favourite components to get a hang of carrying out transactions.
- Checkout prosemirror-utils for more code examples.
#
How do I create a new paragraph node ?Below is an example of how you can create a new paragraph node: