FEATURE: CTRL+/ to trigger search even from composer

This commit is contained in:
Sam 2017-08-02 16:26:03 -04:00
parent a4e1920604
commit 902be91a5a
4 changed files with 38 additions and 5 deletions

View File

@ -234,6 +234,13 @@ export default Ember.Component.extend({
const mouseTrap = Mousetrap(this.$('.d-editor-input')[0]);
const shortcuts = this.get('toolbar.shortcuts');
// for some reason I am having trouble bubbling this so hack it in
mouseTrap.bind(['ctrl+/','command+/'], (event) =>{
this.appEvents.trigger('header:keyboard-trigger', {type: 'search', event});
return true;
});
Object.keys(shortcuts).forEach(sc => {
const button = shortcuts[sc];
mouseTrap.bind(sc, () => {
@ -267,6 +274,7 @@ export default Ember.Component.extend({
const mouseTrap = this._mouseTrap;
Object.keys(this.get('toolbar.shortcuts')).forEach(sc => mouseTrap.unbind(sc));
mouseTrap.unbind('ctrl+/','command+/');
this.$('.d-editor-preview').off('click.preview');
},

View File

@ -6,6 +6,8 @@ const bindings = {
'!': {postAction: 'showFlags'},
'#': {handler: 'goToPost', anonymous: true},
'/': {handler: 'toggleSearch', anonymous: true},
'ctrl+/': {handler: 'toggleSearch', anonymous: true},
'command+/': {handler: 'toggleSearch', anonymous: true},
'=': {handler: 'toggleHamburgerMenu', anonymous: true},
'?': {handler: 'showHelpModal', anonymous: true},
'.': {click: '.alert.alert-info.clickable', anonymous: true}, // show incoming/updated topics

View File

@ -2359,7 +2359,7 @@ en:
hamburger_menu: '<b>=</b> Open hamburger menu'
user_profile_menu: '<b>p</b> Open user menu'
show_incoming_updated_topics: '<b>.</b> Show updated topics'
search: '<b>/</b> Search'
search: '<b>/</b> or <b>ctrl</b>+<b>/</b> Search'
help: '<b>?</b> Open keyboard help'
dismiss_new_posts: '<b>x</b>, <b>r</b> Dismiss New/Posts'
dismiss_topics: '<b>x</b>, <b>t</b> Dismiss Topics'

View File

@ -1,6 +1,6 @@
/*global define:false */
/**
* Copyright 2015 Craig Campbell
* Copyright 2012-2017 Craig Campbell
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -17,11 +17,16 @@
* Mousetrap is a simple keyboard shortcut library for Javascript with
* no external dependencies
*
* @version 1.5.3
* @version 1.6.1
* @url craig.is/killing/mice
*/
(function(window, document, undefined) {
// Check if mousetrap is used inside browser, if not, return
if (!window) {
return;
}
/**
* mapping of special keycodes to their corresponding keys
*
@ -151,7 +156,13 @@
* loop through to map numbers on the numeric keypad
*/
for (i = 0; i <= 9; ++i) {
_MAP[i + 96] = i;
// This needs to use a string cause otherwise since 0 is falsey
// mousetrap will never fire for numpad 0 pressed as part of a keydown
// event.
//
// @see https://github.com/ccampbell/mousetrap/pull/258
_MAP[i + 96] = i.toString();
}
/**
@ -983,6 +994,18 @@
return self._handleKey.apply(self, arguments);
};
/**
* allow custom key mappings
*/
Mousetrap.addKeycodes = function(object) {
for (var key in object) {
if (object.hasOwnProperty(key)) {
_MAP[key] = object[key];
}
}
_REVERSE_MAP = null;
};
/**
* Init the global mousetrap functions
*
@ -1018,4 +1041,4 @@
return Mousetrap;
});
}
}) (window, document);
}) (typeof window !== 'undefined' ? window : null, typeof window !== 'undefined' ? document : null);