Best way to replace entire selection with 1 code block

Right now if I paste in some code as plain text, select all of it, and convert it to a code block with the code block menu (setBlockType) from example-setup, it makes each line/node its own separate code block.

What would be the best way to take the selected text and combine all of it into one code block?

You could get a block range, take its text with textBetween, and replace the entire range with a code block containing that text.