We are using a code editor as you pointed out.
I would agree 100% with your plan if the user was working on the WYS(WYG) side
I guess the question is where do you
stop protecting the user from producing invalid code?
I can already delete any part of tag code, leaving it invalid.
I don't know how hard it would be to Sanity validate the selection and report:
"Selected text contains unbalanced tag pairs"