Index: chrome/browser/resources/md_bookmarks/command_manager.js |
diff --git a/chrome/browser/resources/md_bookmarks/command_manager.js b/chrome/browser/resources/md_bookmarks/command_manager.js |
index efad1e2ec83a5170f1148406f9243605c5bda737..39c11ef02f553d4da1d793f9a4351938b99ec0a1 100644 |
--- a/chrome/browser/resources/md_bookmarks/command_manager.js |
+++ b/chrome/browser/resources/md_bookmarks/command_manager.js |
@@ -18,10 +18,20 @@ Polymer({ |
/** @private {function(!Event)} */ |
this.boundOnOpenItemMenu_ = this.onOpenItemMenu_.bind(this); |
document.addEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
+ |
+ /** @private {function(!Event)} */ |
+ this.boundOnKeydown_ = this.onKeydown_.bind(this); |
+ document.addEventListener('keydown', this.boundOnKeydown_); |
+ |
+ this.shortcuts_ = {}; |
calamity
2017/04/26 10:07:58
This isn't declared or annotated anywhere.
tsergeant
2017/04/27 01:42:51
Done.
|
+ this.shortcuts_[Command.EDIT] = cr.isMac ? 'enter' : 'f2'; |
+ this.shortcuts_[Command.COPY] = cr.isMac ? 'meta+c' : 'ctrl+c'; |
+ this.shortcuts_[Command.DELETE] = cr.isMac ? 'delete backspace' : 'delete'; |
}, |
detached: function() { |
document.removeEventListener('open-item-menu', this.boundOnOpenItemMenu_); |
+ document.removeEventListener('keydown', this.boundOnKeydown_); |
}, |
/** |
@@ -142,6 +152,27 @@ Polymer({ |
}, |
/** |
+ * @param {!Event} e |
+ * @private |
+ */ |
+ onKeydown_: function(e) { |
+ var selection = this.getState().selection.items; |
+ // TODO(tsergeant): Prevent keyboard shortcuts when a dialog is open or text |
+ // field is focused. |
+ for (var commandName in this.shortcuts_) { |
+ var shortcut = this.shortcuts_[commandName]; |
+ if (Polymer.IronA11yKeysBehavior.keyboardEventMatchesKeys(e, shortcut) && |
+ this.canExecute(commandName, selection)) { |
+ this.handle(commandName, selection); |
+ |
+ e.stopPropagation(); |
+ e.preventDefault(); |
+ return; |
+ } |
+ } |
+ }, |
+ |
+ /** |
* Close the menu on mousedown so clicks can propagate to the underlying UI. |
* This allows the user to right click the list while a context menu is |
* showing and get another context menu. |