Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2598)

Unified Diff: chrome/browser/resources/shared/js/cr/ui/list_selection_model.js

Issue 7063007: Revert 86065 - Move sorting logic from table to list. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/shared/js/cr/ui/list_selection_model.js
===================================================================
--- chrome/browser/resources/shared/js/cr/ui/list_selection_model.js (revision 86337)
+++ chrome/browser/resources/shared/js/cr/ui/list_selection_model.js (working copy)
@@ -247,29 +247,43 @@
* @param {!Array.<number>} permutation The reordering permutation.
*/
adjustToReordering: function(permutation) {
- var oldLeadIndex = this.leadIndex;
-
- var oldSelectedIndexes = this.selectedIndexes;
- this.selectedIndexes = oldSelectedIndexes.map(function(oldIndex) {
- return permutation[oldIndex];
- }).filter(function(index) {
- return index != -1;
- });
-
- if (oldLeadIndex != -1)
- this.leadIndex = permutation[oldLeadIndex];
},
/**
- * Adjusts selection model length. This is only used when data model is
- * set, so it is safe to clear() first.
- * This should not be used for dataModel updates, use adjustToReordering
- * instead.
- * @param {number} length New selection model length.
+ * Adjust the selection by adding or removing a certain numbers of items.
+ * This should be called by the owner of the selection model as items are
+ * added and removed from the underlying data model.
+ * @param {number} index The index of the first change.
+ * @param {number} itemsRemoved Number of items removed.
+ * @param {number} itemsAdded Number of items added.
*/
- adjustLength: function(length) {
- this.clear();
- this.length_ = length;
+ adjust: function(index, itemsRemoved, itemsAdded) {
+ function getNewAdjustedIndex(i) {
+ if (i >= index && i < index + itemsRemoved) {
+ return index
+ } else if (i >= index) {
+ return i - itemsRemoved + itemsAdded;
+ }
+ return i;
+ }
+
+ this.length_ += itemsAdded - itemsRemoved;
+
+ var newMap = [];
+ for (var i in this.selectedIndexes_) {
+ i = Number(i);
+ if (i < index) {
+ newMap[i] = true;
+ } else if (i < index + itemsRemoved) {
+ // noop
+ } else {
+ newMap[i + itemsAdded - itemsRemoved] = true;
+ }
+ }
+ this.selectedIndexes_ = newMap;
+
+ this.leadIndex = getNewAdjustedIndex(this.leadIndex);
+ this.anchorIndex = getNewAdjustedIndex(this.anchorIndex);
}
};

Powered by Google App Engine
This is Rietveld 408576698