Refactor Commands into Transform Helpers

The command interface isn’t going to be overhauled again, for the sake finally stabilizing but also because I think their current form expresses what they do better (they may have side effects, beyond dispatching a transaction).

You can extend commands with this slightly awkward but unproblematic pattern:

function andSelectAll(command) {
  return (state, dispatch) => {
    return command(state, dispatch && (tr => {
      if (tr.isGeneric) // Don't touch non-generic transactions
        tr.setSelection(Selection.between(tr.doc.resolve(0),
                                          tr.doc.resolve(tr.doc.content.size)))
      dispatch(tr)
    }))
  }
}

[Edit: Actually balance brackets]

1 Like