Place cursor after math when closing popover

When closing the math popover, the cursor is placed after the math. If you mathify inline using ^m it skips the popover and places the cursor after the math. There was code to do this previously which didn't work that well, and which caused a proliferation of non-breaking space characters.