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

Unified Diff: chrome/browser/resources/md_bookmarks/list.js

Issue 2977523002: MD Bookmarks: Scroll and select items that are added to the main list (Closed)
Patch Set: Fix test Created 3 years, 5 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_bookmarks/list.js
diff --git a/chrome/browser/resources/md_bookmarks/list.js b/chrome/browser/resources/md_bookmarks/list.js
index 7d772a19766b1a8682de44eb493a6f8998e90082..80dd1f5c6e9fd32e7948565617da2a3c30ba5c9c 100644
--- a/chrome/browser/resources/md_bookmarks/list.js
+++ b/chrome/browser/resources/md_bookmarks/list.js
@@ -64,8 +64,19 @@ Polymer({
});
this.updateFromStore();
+ this.boundOnItemKeydown_ = this.onItemKeydown_.bind(this);
+ this.boundOnHighlightItems_ = this.onHighlightItems_.bind(this);
+
this.$.bookmarksCard.addEventListener(
- 'keydown', this.onItemKeydown_.bind(this), true);
+ 'keydown', this.boundOnItemKeydown_, true);
+ document.addEventListener('highlight-items', this.boundOnHighlightItems_);
+ },
+
+ detached: function() {
+ this.$.bookmarksCard.removeEventListener(
+ 'keydown', this.boundOnItemKeydown_, true);
+ document.removeEventListener(
+ 'highlight-items', this.boundOnHighlightItems_);
},
/** @return {HTMLElement} */
@@ -108,6 +119,20 @@ Polymer({
this.scrollTop = 0;
},
+ /**
+ * Scroll the list so that |itemId| is visible, if it is not already.
+ * @param {string} itemId
+ * @private
+ */
+ scrollToId_: function(itemId) {
+ var index = this.displayedIds_.indexOf(itemId);
+ var list = this.$.bookmarksCard;
+ if (index >= 0 && index < list.firstVisibleIndex ||
+ index > list.lastVisibleIndex) {
+ list.scrollToIndex(index);
+ }
+ },
+
/** @private */
emptyListMessage_: function() {
var emptyListMessage = this.searchTerm_ ? 'noSearchResults' : 'emptyList';
@@ -137,12 +162,33 @@ Polymer({
* @private
*/
onOpenItemMenu_: function(e) {
- var index = this.displayedIds_.indexOf(
- /** @type {BookmarksItemElement} */ (e.path[0]).itemId);
- var list = this.$.bookmarksCard;
// If the item is not visible, scroll to it before rendering the menu.
- if (index < list.firstVisibleIndex || index > list.lastVisibleIndex)
- list.scrollToIndex(index);
+ this.scrollToId_(/** @type {BookmarksItemElement} */ (e.path[0]).itemId);
+ },
+
+ /**
+ * Highlight a list of items by selecting them, scrolling them into view and
+ * focusing the first item.
+ * @param {Event} e
+ * @private
+ */
+ onHighlightItems_: function(e) {
+ var toHighlight = /** @type {!Array<string>} */
+ (e.detail.filter((item) => this.displayedIds_.indexOf(item) != -1));
calamity 2017/07/14 04:14:39 Comment plx. What are the cases where this comes u
tsergeant 2017/07/14 06:39:20 This is just being defensive, but I think it's a r
calamity 2017/07/17 05:09:49 Acknowledged.
+
+ assert(toHighlight.length > 0);
+ var leadId = toHighlight[0];
+ this.dispatch(bookmarks.actions.updateAnchor(leadId));
+ this.dispatch(
+ bookmarks.actions.selectAll(toHighlight, this.getState(), leadId));
calamity 2017/07/14 04:14:39 So a batch of operations from a move isn't _guaran
calamity 2017/07/14 04:14:39 leadId is selected as the anchor here and in the p
tsergeant 2017/07/14 06:39:19 Yeah, this is the thing that was hard about this C
tsergeant 2017/07/14 06:39:20 Done.
calamity 2017/07/17 05:09:49 Can we add a completion callback to Drop and Paste
tsergeant 2017/07/18 01:08:54 Done.
+
+ // Allow iron-list time to render changes to the list.
calamity 2017/07/14 04:14:39 What changes need to be rendered here? The adds/re
tsergeant 2017/07/14 06:39:20 Yeah, additions to the list are what's important.
+ this.async(function() {
+ this.scrollToId_(leadId);
+ var leadIndex = this.displayedIds_.indexOf(leadId);
+ assert(leadIndex != -1);
+ this.$.bookmarksCard.focusItem(leadIndex);
calamity 2017/07/14 04:14:39 tangent: I would love to rename bookmarksCard to l
tsergeant 2017/07/14 06:39:19 Renamed to list.
+ });
},
/**

Powered by Google App Engine
This is Rietveld 408576698