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

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

Issue 2885723002: [MD Bookmarks] Add keyboard navigation and selection to bookmark list. (Closed)
Patch Set: address comments Created 3 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
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/browser/resources/md_bookmarks/reducers.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..75810eaaddfd5c0710b7cc919e29a4d1c6105137 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,81 @@ Polymer({
deselectItems_: function() {
this.dispatch(bookmarks.actions.deselectItems());
},
+
+ /** @private */
+ selectAllItems_: function() {
+ this.dispatch(
+ bookmarks.actions.selectAll(this.displayedIds_, this.getState()));
+ },
+
+ /**
+ * @param{HTMLElement} el
+ * @private
+ */
+ getIndexForItemElement_: function(el) {
+ return this.$.bookmarksCard.modelForElement(el).index;
+ },
+
+ /**
+ * @param {KeyboardEvent} e
+ * @private
+ */
+ onItemKeydown_: function(e) {
+ var handled = true;
+ var list = this.$.bookmarksCard;
+ var focusMoved = false;
+ var focusedIndex =
+ this.getIndexForItemElement_(/** @type {HTMLElement} */ (e.target));
+ if (e.key == 'ArrowUp') {
+ focusedIndex--;
+ focusMoved = true;
+ } else if (e.key == 'ArrowDown') {
+ focusedIndex++;
+ focusMoved = true;
+ e.preventDefault();
+ } else if (e.key == 'Home') {
+ focusedIndex = 0;
+ focusMoved = true;
+ } else if (e.key == 'End') {
+ focusedIndex = list.items.length - 1;
+ focusMoved = true;
+ } else if (e.key == ' ' && e.ctrlKey) {
+ this.dispatch(bookmarks.actions.selectItem(
+ this.displayedIds_[focusedIndex], 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) {
+ focusedIndex = Math.min(list.items.length - 1, Math.max(0, focusedIndex));
+ list.focusItem(focusedIndex);
+
+ if (e.ctrlKey && !e.shiftKey) {
+ this.dispatch(
+ bookmarks.actions.updateAnchor(this.displayedIds_[focusedIndex]));
+ } 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(
+ this.displayedIds_[focusedIndex], this.getState(), config));
+ }
+ }
+
+ if (handled)
+ e.stopPropagation();
+ },
});
« no previous file with comments | « chrome/browser/resources/md_bookmarks/item.js ('k') | chrome/browser/resources/md_bookmarks/reducers.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698