Bug 709549 - Adding a new task selects the last item in the task list. r=philipp
authorMatthew Mecca <matthew.mecca@gmail.com>
Mon, 12 Dec 2011 23:30:15 -0500
changeset 8969 78ef1297c71dc1a63e895c86c20f972dcf3e46db
parent 8968 c1e60860f7bfa18a025024370a02d63cf8ce8a2a
child 8970 bcf4d6cb534101be8177ff478d73c0f49e2b6ec2
push id6878
push usermatthew.mecca@gmail.com
push dateTue, 13 Dec 2011 04:35:16 +0000
treeherdercomm-central@78ef1297c71d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersphilipp
bugs709549
Bug 709549 - Adding a new task selects the last item in the task list. r=philipp
calendar/base/content/calendar-task-tree.xml
--- a/calendar/base/content/calendar-task-tree.xml
+++ b/calendar/base/content/calendar-task-tree.xml
@@ -392,33 +392,36 @@
           /**
            * High-level task tree manipulation
            */
 
           addItem: function tTV_addItem(aItem, aDontSort) {
               if (aItem.isCompleted && !this.binding.showCompleted) {
                   return;
               }
-              var index = this.binding.mHash2Index[aItem.hashId];
+
+              let index = this.binding.mHash2Index[aItem.hashId];
               if (index === undefined) {
-                  var index = this.binding.mTaskArray.length;
+                  index = this.binding.mTaskArray.length;
                   this.binding.mTaskArray.push(aItem);
                   this.binding.mHash2Index[aItem.hashId] = index;
                   // The rowCountChanged function takes two arguments, the index where the
                   // first row was inserted and the number of rows to insert.
                   this.treebox.rowCountChanged(index, 1);
-                  this.tree.view.selection.select(index);
               }
-              this.treebox.ensureRowIsVisible(this.rowCount - 1);
 
-              if(aDontSort) {
+              if (aDontSort) {
                 this.binding.recreateHashTable();
               } else {
                 this.binding.sortItems();
               }
+
+              index = this.binding.mHash2Index[aItem.hashId];
+              this.tree.view.selection.select(index);
+              this.treebox.ensureRowIsVisible(index);
           },
 
           removeItem: function tTV_removeItem(aItem, aDontSort) {
               var index = this.binding.mHash2Index[aItem.hashId];
               if (index != undefined) {
                   delete this.binding.mHash2Index[aItem.hashId];
                   this.binding.mTaskArray.splice(index, 1);
                   this.treebox.rowCountChanged(index, -1);