diff --git a/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js b/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js index 789538f04e..55dd6c76f1 100644 --- a/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js +++ b/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js @@ -31,7 +31,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ 'm t': 'div.notification-options li[data-id="2"] a', // mark topic as tracking 'm w': 'div.notification-options li[data-id="3"] a', // mark topic as watching 'n': '#user-notifications', // open notifictions menu - 'o,enter': '#topic-list tr.topic-list-item.selected a.title', // open selected topic + 'o,enter': '#topic-list tr.selected a.title', // open selected topic 'shift+r': '#topic-footer-buttons button.create', // reply to topic 'r': '.topic-post.selected button.create', // reply to selected post 'shift+s': '#topic-footer-buttons button.share', // share topic @@ -48,7 +48,8 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ '`': 'nextSection', '~': 'prevSection', '/': 'showSearch', - '?': 'showHelpModal' // open keyboard shortcut help + '?': 'showHelpModal', // open keyboard shortcut help + 'q': 'quoteReply' }, bindEvents: function(keyTrapper) { @@ -58,6 +59,14 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ _.each(this.FUNCTION_BINDINGS, this._bindToFunction, this); }, + quoteReply: function(){ + $('.topic-post.selected button.create').click(); + // lazy but should work for now + setTimeout(function(){ + $('#wmd-quote-post').click(); + }, 500); + }, + goToFirstPost: function() { this._jumpTo('jumpTop'); }, @@ -133,25 +142,53 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ // loop is not allowed if (direction === -1 && index === 0) { return; } + // if nothing is selected go to the first post on screen + if ($selected.length === 0) { + var scrollTop = $('body').scrollTop(); + + index = 0; + $articles.each(function(){ + var top = $(this).position().top; + if(top > scrollTop) { + return false; + } + index += 1; + }); + + if(index >= $articles.length){ + index = $articles.length - 1; + } + } + var $article = $articles.eq(index + direction); if ($article.size() > 0) { $articles.removeClass('selected'); - $article.addClass('selected'); + Em.run.next(function(){ + $article.addClass('selected'); + }); var rgx = new RegExp("post-cloak-(\\d+)").exec($article.parent()[0].id); if (rgx === null || typeof rgx[1] === 'undefined') { - this._scrollList($article); + this._scrollList($article, direction); } else { Discourse.TopicView.jumpToPost(rgx[1]); } } }, - _scrollList: function($article) { + _scrollList: function($article, direction) { var $body = $('body'), distToElement = $article.position().top + $article.height() - $(window).height() - $body.scrollTop(); + // cut some bottom slack + distToElement += 40; + + // don't scroll backwards, its silly + if((direction > 0 && distToElement < 0) || (direction < 0 && distToElement > 0)) { + return; + } + $('html, body').scrollTop($body.scrollTop() + distToElement); }, @@ -160,7 +197,7 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ $topicArea = $('.posts-wrapper'); if ($topicArea.size() > 0) { - return $topicArea.find('.topic-post'); + return $('.posts-wrapper .topic-post, #topic-list tbody tr'); } else if ($topicList.size() > 0) { return $topicList.find('.topic-list-item'); diff --git a/app/assets/javascripts/discourse/templates/modal/keyboard_shortcuts_help.js.handlebars b/app/assets/javascripts/discourse/templates/modal/keyboard_shortcuts_help.js.handlebars index faf41abf57..b2e64bdddb 100644 --- a/app/assets/javascripts/discourse/templates/modal/keyboard_shortcuts_help.js.handlebars +++ b/app/assets/javascripts/discourse/templates/modal/keyboard_shortcuts_help.js.handlebars @@ -35,6 +35,7 @@