#896: Ensure updateMap calls endCompoundOperation

Ensure endCompoundOperation is called whenever beginCompoundOperation completes, even if removeRange (or anything in the range) fails. Moreover, call removeRange only when there is text to remove, since apparently the realtime API complains otherwise.