Inserting inside of a nodes contents

I’m trying to manipulate a Gallery node we’ve created by adding a NodeView with buttons that insert nodes into its content. I’m currently trying to re-use our regular insertion command from our menu item which eventually boils down to:

dispatch(state.tr.insert(state.tr.selection.$anchor.pos, subElement))

I’ve been trying variations on insertPoint and dropPoint but they seem to always agree with either $anchor or $head. I’ve tried blindly adding 1 to the anchor position, but while that works with my gallery it, naturally, jumps a spot outside of it.

I think I probably need to separate my insertion logic out, but then I’m lost as to how best to calculate my insertion point based on the current selection. If the selection is inside a gallery with multiple existing images for instance I just want to use the current selection’s $anchor. If the gallery is not around the selection I probably just want to drop the image at the gallery’s getPos() + node.content.size. Per usual, I’m a bit out of my depth even after a couple years and more than one pass through the ol’ guide, but I appreciate all the help and pointers I’ve received here.

OK, made a separate Picker for adding images inside the gallery node. Using getPos() + content.size + 1 to put insertion point at the end of the node. Works a treat.