From 66b6d6c4dd1ea1803aa1b15d33408db12f98e6d2 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 5 Jun 2014 10:23:42 +1000 Subject: [PATCH] BUGFIX: limit hijacking of search for places that have infinite lists of stuff. --- .../discourse/lib/keyboard_shortcuts.js | 28 +++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js b/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js index b6362c34da5..a043315d47a 100644 --- a/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js +++ b/app/assets/javascripts/discourse/lib/keyboard_shortcuts.js @@ -48,8 +48,8 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ '`': 'nextSection', '~': 'prevSection', '/': 'showSearch', - 'ctrl+f': 'showSearch', - 'command+f': 'showSearch', + 'ctrl+f': 'showBuiltinSearch', + 'command+f': 'showBuiltinSearch', '?': 'showHelpModal', // open keyboard shortcut help 'q': 'quoteReply' }, @@ -103,6 +103,30 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ this._changeSection(-1); }, + showBuiltinSearch: function() { + var routeName = _.map(Discourse.Router.router.currentHandlerInfos, "name").join("_"); + var blacklist = [ + /^application_discovery_discovery.categories/ + ]; + + var whitelist = [ + /^application_topic_/, + /^application_discovery_discovery/, + /^application_user_userActivity/ + ]; + + var check = function(regex){return routeName.match(regex);}; + + var whitelisted = _.any(whitelist, check); + var blacklisted = _.any(blacklist, check); + + if(whitelisted && !blacklisted){ + return this.showSearch(); + } else { + return true; + } + }, + showSearch: function() { $('#search-button').click(); return false;