Chromium Code Reviews| Index: chrome/browser/resources/shared/js/cr/ui/list_selection_model.js |
| diff --git a/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js b/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js |
| index 8c16d577f5f2f9d5105df1511ebdbad9fabec353..556085e4727ae3f2421cf4a49ec456cce8551748 100644 |
| --- a/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js |
| +++ b/chrome/browser/resources/shared/js/cr/ui/list_selection_model.js |
| @@ -143,12 +143,7 @@ cr.define('cr.ui', function() { |
| this.beginChange(); |
| - // Changing back? |
| - if (index in this.changedIndexes_ && this.changedIndexes_[index] == !b) { |
| - delete this.changedIndexes_[index]; |
| - } else { |
| - this.changedIndexes_[index] = b; |
| - } |
| + this.changedIndexes_[index] = b; |
| // End change dispatches an event which in turn may update the view. |
| this.endChange(); |
| @@ -182,6 +177,19 @@ cr.define('cr.ui', function() { |
| endChange: function() { |
| this.changeCount_--; |
| if (!this.changeCount_) { |
| + // Calls delayed |dispatchPropertyChange|s. |
|
arv (Not doing code reviews)
2011/11/21 20:38:01
Can you explain why this is needed?
yoshiki
2011/11/28 11:03:31
Done.
|
| + if (this.oldLeadIndex_ != null) { |
| + cr.dispatchPropertyChange(this, 'leadIndex', |
| + this.leadIndex_, this.oldLeadIndex_); |
| + this.oldLeadIndex_ = null; |
| + } |
| + |
| + if (this.oldAnchorIndex_ != null) { |
| + cr.dispatchPropertyChange(this, 'anchorIndex', |
| + this.anchorIndex_, this.oldAnchorIndex_); |
| + this.oldAnchorIndex_ = null; |
| + } |
| + |
| var indexes = Object.keys(this.changedIndexes_); |
| if (indexes.length) { |
| var e = new Event('change'); |
| @@ -198,6 +206,7 @@ cr.define('cr.ui', function() { |
| }, |
| leadIndex_: -1, |
| + oldLeadIndex_: null, |
| /** |
| * The leadIndex is used with multiple selection and it is the index that |
| @@ -212,11 +221,19 @@ cr.define('cr.ui', function() { |
| if (li != this.leadIndex_) { |
| var oldLeadIndex = this.leadIndex_; |
| this.leadIndex_ = li; |
| - cr.dispatchPropertyChange(this, 'leadIndex', li, oldLeadIndex); |
| + |
| + // Delays the call of dispatchPropertyChange if batch is running. |
| + if (this.changeCount_) { |
| + if (this.oldLeadIndex_ == null) |
| + this.oldLeadIndex_ = oldLeadIndex; |
| + } else { |
| + cr.dispatchPropertyChange(this, 'leadIndex', li, oldLeadIndex); |
| + } |
| } |
| }, |
| anchorIndex_: -1, |
| + oldAnchorIndex_: null, |
| /** |
| * The anchorIndex is used with multiple selection. |
| @@ -230,7 +247,14 @@ cr.define('cr.ui', function() { |
| if (ai != this.anchorIndex_) { |
| var oldAnchorIndex = this.anchorIndex_; |
| this.anchorIndex_ = ai; |
| - cr.dispatchPropertyChange(this, 'anchorIndex', ai, oldAnchorIndex); |
| + |
| + // Delays the call of dispatchPropertyChange if batch is running. |
| + if (this.changeCount_) { |
| + if (this.oldAnchorIndex_ == null) |
| + this.oldAnchorIndex_ = oldAnchorIndex; |
| + } else { |
| + cr.dispatchPropertyChange(this, 'anchorIndex', ai, oldAnchorIndex); |
| + } |
| } |
| }, |