mirror of
https://github.com/discourse/discourse.git
synced 2024-11-28 10:15:48 +08:00
FEATURE: Close search window when Ctrl+F is pressed.
FIX: All search related keyboard shortcuts enabled the "search context", but only Ctrl+F inside of topics should enable it.
This commit is contained in:
parent
56ec41cd83
commit
3e2653d198
|
@ -59,6 +59,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
bindEvents: function(keyTrapper, container) {
|
||||
this.keyTrapper = keyTrapper;
|
||||
this.container = container;
|
||||
this._stopCallback();
|
||||
|
||||
_.each(PATH_BINDINGS, this._bindToPath, this);
|
||||
_.each(CLICK_BINDINGS, this._bindToClick, this);
|
||||
|
@ -128,6 +129,11 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
},
|
||||
|
||||
showBuiltinSearch: function() {
|
||||
if ($('#search-dropdown').is(':visible')) {
|
||||
this._toggleSearch(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
var currentPath = this.container.lookup('controller:application').get('currentPath'),
|
||||
blacklist = [ /^discovery\.categories/ ],
|
||||
whitelist = [ /^topic\./ ],
|
||||
|
@ -137,10 +143,14 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
// If we're viewing a topic, only intercept search if there are cloaked posts
|
||||
if (showSearch && currentPath.match(/^topic\./)) {
|
||||
showSearch = $('.cooked').length < this.container.lookup('controller:topic').get('postStream.stream.length');
|
||||
|
||||
}
|
||||
|
||||
return showSearch ? this.showSearch(true) : true;
|
||||
if (showSearch) {
|
||||
this._toggleSearch(true);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
},
|
||||
|
||||
createTopic: function() {
|
||||
|
@ -155,11 +165,8 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
Discourse.__container__.lookup('controller:topic-progress').send('toggleExpansion', {highlight: true});
|
||||
},
|
||||
|
||||
showSearch: function(selectContext) {
|
||||
$('#search-button').click();
|
||||
if(selectContext) {
|
||||
Discourse.__container__.lookup('controller:search').set('searchContextEnabled', true);
|
||||
}
|
||||
showSearch: function() {
|
||||
this._toggleSearch(false);
|
||||
return false;
|
||||
},
|
||||
|
||||
|
@ -340,5 +347,24 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({
|
|||
if(index >= 0 && index < $sections.length){
|
||||
$sections.eq(index).find('a').click();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_stopCallback: function() {
|
||||
var oldStopCallback = this.keyTrapper.stopCallback;
|
||||
|
||||
this.keyTrapper.stopCallback = function(e, element, combo) {
|
||||
if ((combo === 'ctrl+f' || combo === 'command+f') && element.id === 'search-term') {
|
||||
return false;
|
||||
}
|
||||
|
||||
return oldStopCallback(e, element, combo);
|
||||
};
|
||||
},
|
||||
|
||||
_toggleSearch: function(selectContext) {
|
||||
$('#search-button').click();
|
||||
if (selectContext) {
|
||||
Discourse.__container__.lookup('controller:search').set('searchContextEnabled', true);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user