From 80fdea7bfb20bb1f38e46c623f26e840a64db42e Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Wed, 18 Jul 2012 14:17:50 -0600 Subject: [PATCH] Fix #437. Add hotkey support using mousetrap. --- .../gollum/javascript/editor/gollum.editor.js | 20 +++++++++++++------ lib/gollum/frontend/templates/editor.mustache | 2 +- lib/gollum/frontend/templates/layout.mustache | 1 + 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js b/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js index 8dee8aef..53f24e31 100755 --- a/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js +++ b/lib/gollum/frontend/public/gollum/javascript/editor/gollum.editor.js @@ -24,7 +24,6 @@ * You don't need to do anything. Just run this on DOM ready. */ $.GollumEditor = function( IncomingOptions ) { - ActiveOptions = $.extend( DefaultOptions, IncomingOptions ); debug('GollumEditor loading'); @@ -96,11 +95,8 @@ $('#gollum-editor-help').hide(); $('#gollum-editor-help').removeClass('jaws'); } - - } - // EditorHas.functionBar - } - // EditorHas.baseEditorMarkup + } // EditorHas.functionBar + } // EditorHas.baseEditorMarkup }; @@ -199,6 +195,18 @@ if(LanguageDefinition.getHookFunctionFor("activate")) { LanguageDefinition.getHookFunctionFor("activate")(); } + + function hotkey( cmd ) { + var def = LanguageDefinition.getDefinitionFor( cmd ); + if ( typeof def == 'object' ) { + FunctionBar.executeAction( def ); + } + // Prevent bubbling of hotkey. + return false; + } + + Mousetrap.bind(['command+b', 'ctrl+b'], function(){ hotkey('function-bold'); }); + Mousetrap.bind(['command+i', 'ctrl+i'], function(){ hotkey('function-italic'); }); } ); } else { LanguageDefinition._ACTIVE_LANG = name; diff --git a/lib/gollum/frontend/templates/editor.mustache b/lib/gollum/frontend/templates/editor.mustache index d81cd4ec..94c7fd51 100644 --- a/lib/gollum/frontend/templates/editor.mustache +++ b/lib/gollum/frontend/templates/editor.mustache @@ -88,7 +88,7 @@ + data-markup-lang="{{format}}" name="content" class="mousetrap">{{content}} {{#header}}