These two (insertLineBefore and insertLineAfter) are similar enough that you should probably define a helper function that performs the logic, and call that (with an argument to distinguish between the two cases) from the command functions.

Make sure you wrap the actions in a call to `cm.command` when making more than one change. This prevents multiple (expensive) display updates, and ensures that the effect will be a single undo event.

Also, you can probably simply gather the selections in an array and call `setSelections` once to add them.