Support 'shared' option to setBookmark

Issue #2360
Always merge matching-origin selection event after change

Issue #2305
Fix error when running undoSelection on empty history