Restore focus after an undo or redo operation

Recent changes introduced in 26a9252 caused the focus to no longer be correctly restored after replacing the document root.

Additionally, don't re-capture focus when the cursor is re-added to the document. Performing the focus capture when a cursor is registered to the document causes undo/redo to slow down, as the focus gets pulled into the cursor as soon as the AddCursor op is executed. The focus should not be changed while executing operations.

Fixes issue #397