diff options
author | Florent Baldino <fbaldino@onisep.fr> | 2016-03-07 17:35:26 +0300 |
---|---|---|
committer | Florent Baldino <fbaldino@onisep.fr> | 2016-03-07 17:35:26 +0300 |
commit | af24645d5d25642f462dea5bacd81908b852c493 (patch) | |
tree | eb10651eaef271772c260098546e5f3ba41d6ce0 /app/assets/javascripts/shortcuts.js.coffee | |
parent | be1ae2d660ad98cf6a44cefa3148f9c48b66806f (diff) |
Add shortcut to toggle markdown preview
Diffstat (limited to 'app/assets/javascripts/shortcuts.js.coffee')
-rw-r--r-- | app/assets/javascripts/shortcuts.js.coffee | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/app/assets/javascripts/shortcuts.js.coffee b/app/assets/javascripts/shortcuts.js.coffee index 9c7c2474aa4..100e3aac535 100644 --- a/app/assets/javascripts/shortcuts.js.coffee +++ b/app/assets/javascripts/shortcuts.js.coffee @@ -4,11 +4,15 @@ class @Shortcuts Mousetrap.reset() Mousetrap.bind('?', @selectiveHelp) Mousetrap.bind('s', Shortcuts.focusSearch) + Mousetrap.bind(['ctrl+shift+p', 'command+shift+p'], @toggleMarkdownPreview) Mousetrap.bind('t', -> Turbolinks.visit(findFileURL)) if findFileURL? selectiveHelp: (e) => Shortcuts.showHelp(e, @enabledHelp) + toggleMarkdownPreview: (e) => + $(document).triggerHandler('markdown-preview:toggle', [e]) + @showHelp: (e, location) -> if $('#modal-shortcuts').length > 0 $('#modal-shortcuts').modal('show') @@ -35,3 +39,14 @@ $(document).on 'click.more_help', '.js-more-help-button', (e) -> $(@).remove() $('.hidden-shortcut').show() e.preventDefault() + +Mousetrap.stopCallback = (-> + defaultStopCallback = Mousetrap.stopCallback + + return (e, element, combo) -> + # allowed shortcuts if textarea, input, contenteditable are focused + if ['ctrl+shift+p', 'command+shift+p'].indexOf(combo) != -1 + return false + else + return defaultStopCallback.apply(@, arguments) +)() |