How to select paragraph nodes in a selection that spans across multiple paragraphs?

I would like to know how do we access the paragraph nodes that are “overlapped” by the selection as I want to perform a bulk modification to all the selected paragraph nodes.

And the follow up question is how do we combine all the modifications into one transaction?

Depending on what you want exactly, the blockRange method might be useful to get a range of all (partially) selected blocks. Combining modification in a transaction is just a matter of calling methods on the same transaction object until all your modifications are in there (though if your changes cause positions to shift because they insert or delete content, you have to be careful about mapping the positions of later changes).

not sure if i understand the usage of blockRange.

i had this code to (kinda?) achieve what I wanted? would like to know if it is the correct way to do it

function toTextAlign(align: string) {
  const paragraphType = view.state.schema.nodes.paragraph;
  const { $from, $to } = view.state.selection;
  const nodeRange = $from.blockRange($to);
  const parent = nodeRange.parent;

  let tr: Transaction<any> = view.state.tr;
  parent.nodesBetween(
    nodeRange.start,
    nodeRange.end,
    (node, pos, parent, index) => {
      if (node.type.name === "paragraph" || node.type.name === "heading") {
        tr = tr.setNodeMarkup(pos, undefined, {
          "text-align": align
        });
      }
    }
  );
  view.dispatch(tr);
  view.focus();
}