01 · Before and afterThe pattern
// one predicate feeds both isActive() and apply()
function canConvert(state, pos, targetType) {
const $pos = state.doc.resolve(pos);
return $pos.parent.canReplaceWith($pos.index(), $pos.index() + 1, targetType);
}
const targets = blocksInSelection(state).filter((b) => canConvert(state, b.pos, targetType));02 · Run it on your appThe check
For each toggle in your editor or UI, does “is it on?” use the same code path as “turn it on”, and is there a test that toggles twice?
If the honest answer is no or not sure, this is worth a look before it reaches production.