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 07951140491ba312e760b37f12ed3423dcf921ae..60e1d6b655676fd0dd3f9da534cffa4fa7b9b61f 100644 |
--- a/chrome/browser/resources/md_bookmarks/list.js |
+++ b/chrome/browser/resources/md_bookmarks/list.js |
@@ -50,6 +50,9 @@ Polymer({ |
return state.search.term; |
}); |
this.updateFromStore(); |
+ |
+ this.$.bookmarksCard.addEventListener( |
+ 'keydown', this.onItemKeydown_.bind(this), true); |
}, |
/** @return {HTMLElement} */ |
@@ -100,4 +103,68 @@ Polymer({ |
deselectItems_: function() { |
this.dispatch(bookmarks.actions.deselectItems()); |
}, |
+ |
+ /** @private */ |
+ selectAllItems_: function() { |
+ this.dispatch( |
+ bookmarks.actions.selectAll(this.displayedIds_, this.getState())); |
+ }, |
+ |
+ /** |
+ * @param {KeyboardEvent} e |
+ * @private |
+ */ |
+ onItemKeydown_: function(e) { |
+ var handled = true; |
+ var list = this.$.bookmarksCard; |
+ var focusMoved = false; |
+ if (e.key == 'ArrowUp') { |
+ list.focusPhysicalItem(list.getFocusedIndex() - 1); |
+ focusMoved = true; |
+ } else if (e.key == 'ArrowDown') { |
+ list.focusPhysicalItem(list.getFocusedIndex() + 1); |
+ focusMoved = true; |
+ e.preventDefault(); |
+ } else if (e.key == 'Home') { |
+ list.focusPhysicalItem(0); |
+ focusMoved = true; |
+ } else if (e.key == 'End') { |
+ list.focusPhysicalItem(list.items.length - 1); |
+ focusMoved = true; |
+ } else if (e.key == ' ' && e.ctrlKey) { |
+ this.dispatch(bookmarks.actions.selectItem( |
+ list.getFocusedItem().itemId, this.getState(), { |
+ clear: false, |
+ range: false, |
+ toggle: true, |
+ })); |
+ } else if (e.key == 'a' && e.ctrlKey) { |
+ this.selectAllItems_(); |
+ } else if (e.key == 'Escape') { |
+ this.deselectItems_(); |
+ } else { |
+ handled = false; |
+ } |
+ |
+ if (focusMoved) { |
+ if (e.ctrlKey && !e.shiftKey) { |
+ this.dispatch( |
+ bookmarks.actions.updateAnchor(list.getFocusedItem().itemId)); |
+ } else { |
+ // If the focus moved from something other than a Ctrl + move event, |
+ // update the selection. |
+ var config = { |
+ clear: !e.ctrlKey, |
+ range: e.shiftKey, |
+ toggle: false, |
+ }; |
+ |
+ this.dispatch(bookmarks.actions.selectItem( |
+ list.getFocusedItem().itemId, this.getState(), config)); |
+ } |
+ } |
+ |
+ if (handled) |
+ e.stopPropagation(); |
+ }, |
}); |