From 9181ea5f8aa6ea61219e29a44f1d67cc721b784b Mon Sep 17 00:00:00 2001
From: "Paolo G. Giarrusso"
Date: Sat, 8 Nov 2014 19:11:44 +0100
Subject: [PATCH] #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.
---
plugins/sync.user.js | 31 ++++++++++++++++++-------------
1 file changed, 18 insertions(+), 13 deletions(-)
diff --git a/plugins/sync.user.js b/plugins/sync.user.js
index 388ad864..882578af 100644
--- a/plugins/sync.user.js
+++ b/plugins/sync.user.js
@@ -119,19 +119,24 @@ window.plugin.sync.RegisteredMap.prototype.updateMap = function(keyArray) {
var _this = this;
// Use compound operation to ensure update pushed as a batch
this.model.beginCompoundOperation();
- // Remove before set text to ensure full text change
- this.lastUpdateUUID.removeRange(0, this.lastUpdateUUID.length);
- this.lastUpdateUUID.setText(this.uuid);
-
- $.each(keyArray, function(ind, key) {
- var value = window.plugin[_this.pluginName][_this.fieldName][key];
- if(typeof(value) !== 'undefined') {
- _this.map.set(key, value);
- } else {
- _this.map.delete(key);
- }
- });
- this.model.endCompoundOperation();
+ try {
+ // Remove before set text to ensure full text change
+ if (this.lastUpdateUUID.length > 0)
+ this.lastUpdateUUID.removeRange(0, this.lastUpdateUUID.length);
+ this.lastUpdateUUID.setText(this.uuid);
+
+ $.each(keyArray, function(ind, key) {
+ var value = window.plugin[_this.pluginName][_this.fieldName][key];
+ if(typeof(value) !== 'undefined') {
+ _this.map.set(key, value);
+ } else {
+ _this.map.delete(key);
+ }
+ });
+ } finally {
+ // Ensure endCompoundOperation is always called (see bug #896)
+ this.model.endCompoundOperation();
+ }
}
window.plugin.sync.RegisteredMap.prototype.isUpdatedByOthers = function() {