#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.
This commit is contained in:
Paolo G. Giarrusso 2014-11-08 19:11:44 +01:00
parent 199a9f15dd
commit 9181ea5f8a

View File

@ -119,7 +119,9 @@ window.plugin.sync.RegisteredMap.prototype.updateMap = function(keyArray) {
var _this = this; var _this = this;
// Use compound operation to ensure update pushed as a batch // Use compound operation to ensure update pushed as a batch
this.model.beginCompoundOperation(); this.model.beginCompoundOperation();
try {
// Remove before set text to ensure full text change // Remove before set text to ensure full text change
if (this.lastUpdateUUID.length > 0)
this.lastUpdateUUID.removeRange(0, this.lastUpdateUUID.length); this.lastUpdateUUID.removeRange(0, this.lastUpdateUUID.length);
this.lastUpdateUUID.setText(this.uuid); this.lastUpdateUUID.setText(this.uuid);
@ -131,8 +133,11 @@ window.plugin.sync.RegisteredMap.prototype.updateMap = function(keyArray) {
_this.map.delete(key); _this.map.delete(key);
} }
}); });
} finally {
// Ensure endCompoundOperation is always called (see bug #896)
this.model.endCompoundOperation(); this.model.endCompoundOperation();
} }
}
window.plugin.sync.RegisteredMap.prototype.isUpdatedByOthers = function() { window.plugin.sync.RegisteredMap.prototype.isUpdatedByOthers = function() {
var remoteUUID = this.lastUpdateUUID.toString(); var remoteUUID = this.lastUpdateUUID.toString();