Restore focus to the event trap if reset by an operation

With the event trap now being inside the cursor, any repositioning of
the cursor causes the document.activeElement and window selection to
change. This causes the document to stop being editable after actions
such as bolding current text.

Now, the focus state of the event trap is checked prior to each
operation, and will be reset back to the event trap if disrupted by an
operation. Note, checks are in place to prevent stealing focus if the
document is not active when an operation is executed.

Fixes issue #298
Merge pull request #301 from peitschie/focus-fix

Restore focus to the event trap if reset by an operation
Capture cursor registration for undo event even when not in edit mode

Any cursor add or removal commands should be tracked for the purposes
of restoring the document state. If a cursor operation is missed, the
document will not re-add the cursor after an undo operation.
Don’t reset the undo manager state when entering or exiting edit mode

This allows consumers to enter and exit edit mode multiple times without
the undo stack being reset. Once the initial undo state has been captured
after the document is loaded, there is no major problems with preserving
the undo state (other than the undo manager’s shameful performance).