Spell Checker Implementation

I am new to prosemirror. Trying to implement a spell checker following this example ProseMirror lint example In the example it says to use transactions to find out which portion of the document is changed , and to do the spell check only on that part. But i did not see much documentation(or may be i am not understanding what ever is there) on it. Any one who can point me to an example for finding the changed part of the document?

Basically you iterate through the steps in the transaction getting their extent from the step maps, and mapping the previous positions forward to account for subsequent steps. Something like this:

function touchedRange(tr: Transaction) {
  let from = 1e9, to = -1
  for (let map of tr.mapping.maps) {
    if (to >= 0) {
      from = map.map(from, -1)
      to = map.map(to, 1)
    map.forEach((oldStart, oldEnd, newStart, newEnd) => {
      from = Math.min(from, newStart)
      to = Math.max(to, newEnd)
  return to < 0 ? null : {from, to}
1 Like

Thank you. WIll try that.

Also, a related question, Can a button outside of the editor trigger an event with in? I am trying to use a button to do the spell check rather than doing it as we type.

If you keep a reference to the EditorView, you can dispatch a transaction and use setMeta to set a meta field that you can use to communicate with your plugin. For example, to switch an “isActive” state field on and off.

Thank you . That worked…