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

Unified Diff: ui/webui/resources/js/cr/ui/command.js

Issue 2939873004: MD Bookmarks: Fix issue where keyboard shortcuts could fire incorrectly (Closed)
Patch Set: Fix mac test? Created 3 years, 6 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/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/webui/resources/js/cr/ui/command.js
diff --git a/ui/webui/resources/js/cr/ui/command.js b/ui/webui/resources/js/cr/ui/command.js
index 783bba571da75e69c0b02d29eee20e4b4ba64ede..cdf55b19bdd5a4b31e14aa62998cf8738f1e417f 100644
--- a/ui/webui/resources/js/cr/ui/command.js
+++ b/ui/webui/resources/js/cr/ui/command.js
@@ -64,6 +64,32 @@ cr.define('cr.ui', function() {
}
};
+ /**
+ * A list of keyboard shortcuts which all perform one command.
+ * @param {string} shortcuts Text-based representation of one or more keyboard
+ * shortcuts, separated by spaces.
+ * @constructor
+ */
+ function KeyboardShortcutList(shortcuts) {
+ this.shortcuts_ = shortcuts.split(/\s+/).map(function(shortcut) {
+ return new KeyboardShortcut(shortcut);
+ });
+ }
+
+ KeyboardShortcutList.prototype = {
+ /**
+ * Returns true if any of the keyboard shortcuts in the list matches a
+ * keyboard event.
+ * @param {!Event} e
+ * @return {boolean}
+ */
+ matchesEvent: function(e) {
+ return this.shortcuts_.some(function(keyboardShortcut) {
+ return keyboardShortcut.matchesEvent(e);
+ });
+ },
+ };
+
/**
* Creates a new command element.
* @constructor
@@ -135,9 +161,7 @@ cr.define('cr.ui', function() {
set shortcut(shortcut) {
var oldShortcut = this.shortcut_;
if (shortcut !== oldShortcut) {
- this.keyboardShortcuts_ = shortcut.split(/\s+/).map(function(shortcut) {
- return new KeyboardShortcut(shortcut);
- });
+ this.keyboardShortcuts_ = new KeyboardShortcutList(shortcut);
// Set this after the keyboardShortcuts_ since that might throw.
this.shortcut_ = shortcut;
@@ -154,10 +178,7 @@ cr.define('cr.ui', function() {
matchesEvent: function(e) {
if (!this.keyboardShortcuts_)
return false;
-
- return this.keyboardShortcuts_.some(function(keyboardShortcut) {
- return keyboardShortcut.matchesEvent(e);
- });
+ return this.keyboardShortcuts_.matchesEvent(e);
},
};
@@ -323,5 +344,9 @@ cr.define('cr.ui', function() {
};
// Export
- return {Command: Command, CanExecuteEvent: CanExecuteEvent};
+ return {
+ Command: Command,
+ CanExecuteEvent: CanExecuteEvent,
+ KeyboardShortcutList: KeyboardShortcutList,
+ };
});
« no previous file with comments | « chrome/test/data/webui/md_bookmarks/md_bookmarks_focus_test.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698