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

Unified Diff: chrome/browser/resources/md_history/history_list_behavior.js

Issue 2239623002: [MD History] Add shift-selection to the history lists. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@reshadow
Patch Set: Set => Array Created 4 years, 4 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/md_history/history_list_behavior.js
diff --git a/chrome/browser/resources/md_history/history_list_behavior.js b/chrome/browser/resources/md_history/history_list_behavior.js
index 0716b841f2f83139ab34f0cae7d68acbe5ab4512..cb988dc1137831612518571ff0f20eb323858e11 100644
--- a/chrome/browser/resources/md_history/history_list_behavior.js
+++ b/chrome/browser/resources/md_history/history_list_behavior.js
@@ -31,12 +31,14 @@ var HistoryListBehavior = {
properties: {
/**
* Polymer paths to the history items contained in this list.
- * @type {Array<string>} selectedPaths
+ * @type {Set<string>} selectedPaths
*/
selectedPaths: {
- type: Array,
- value: /** @return {Array<string>} */ function() { return []; }
+ type: Object,
+ value: /** @return {Set<string>} */ function() { return new Set(); }
},
+
+ lastSelectedPath: String,
},
listeners: {
@@ -72,7 +74,7 @@ var HistoryListBehavior = {
this.set(path + '.selected', false);
}.bind(this));
- this.selectedPaths = [];
+ this.selectedPaths.clear();
},
/**
@@ -82,13 +84,15 @@ var HistoryListBehavior = {
* does prompt.
*/
deleteSelected: function() {
- var toBeRemoved = this.selectedPaths.map(function(path) {
- return this.get(path);
- }.bind(this));
+ var toBeRemoved =
+ Array.from(this.selectedPaths.values()).map(function(path) {
+ return this.get(path);
+ }.bind(this));
+
md_history.BrowserService.getInstance()
.deleteItems(toBeRemoved)
.then(function() {
- this.removeItemsByPath(this.selectedPaths);
+ this.removeItemsByPath(Array.from(this.selectedPaths));
this.fire('unselect-all');
}.bind(this));
},
@@ -107,7 +111,7 @@ var HistoryListBehavior = {
* @private
*/
removeItemsByPath: function(paths) {
- if (paths.length == 0)
+ if (paths.size == 0)
return;
this.removeItemsBeneathNode_(this.buildRemovalTree_(paths));
@@ -155,6 +159,9 @@ var HistoryListBehavior = {
*/
removeItemsBeneathNode_: function(node) {
var array = this.get(node.currentPath);
+ if (array.length == 0)
+ return true;
+
var splices = [];
node.indexes.sort(function(a, b) { return b - a; });
@@ -171,9 +178,6 @@ var HistoryListBehavior = {
}
}.bind(this));
- if (array.length == 0)
- return true;
-
// notifySplices gives better performance than individually splicing as it
// batches all of the updates together.
this.notifySplices(node.currentPath, splices);
@@ -186,14 +190,40 @@ var HistoryListBehavior = {
*/
itemSelected_: function(e) {
var item = e.detail.element;
- var path = item.path;
- if (item.selected) {
- this.push('selectedPaths', path);
- return;
+ var paths = [];
+ var itemPath = item.path;
+
+ // Handle shift selection. Change the selection state of all items between
+ // |path| and |lastSelected| to the selection state of |item|.
+ if (e.detail.shiftKey && this.lastSelectedPath) {
+ var itemPathComponents = itemPath.split('.');
+ var itemIndex = Number(itemPathComponents.pop());
+ var itemArrayPath = itemPathComponents.join('.');
+
+ var lastItemPathComponents = this.lastSelectedPath.split('.');
+ var lastItemIndex = Number(lastItemPathComponents.pop());
+ if (itemArrayPath == lastItemPathComponents.join('.')) {
+ for (var i = Math.min(itemIndex, lastItemIndex);
+ i <= Math.max(itemIndex, lastItemIndex); i++) {
+ paths.push(itemArrayPath + '.' + i);
+ }
+ }
}
- var index = this.selectedPaths.indexOf(path);
- if (index != -1)
- this.splice('selectedPaths', index, 1);
+ if (paths.length == 0)
+ paths.push(item.path);
+
+ paths.forEach(function(path) {
+ this.set(path + '.selected', item.selected);
+
+ if (item.selected) {
+ this.selectedPaths.add(path);
+ return;
+ }
+
+ this.selectedPaths.delete(path);
+ }.bind(this));
+
+ this.lastSelectedPath = itemPath;
},
};

Powered by Google App Engine
This is Rietveld 408576698