From bb887964b16ea9cf0e1ced8005dfd990069c7400 Mon Sep 17 00:00:00 2001 From: Sam Date: Thu, 29 May 2014 15:38:06 +1000 Subject: [PATCH] BUGFIX: j/k now goes to the suggested topic list correctly. --- .../components/keyboard_shortcuts_component.js | 16 ++++++++++++---- .../components/keyboard_shortcuts.css.scss | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js b/app/assets/javascripts/discourse/components/keyboard_shortcuts_component.js index 789538f04ec..7d9210be0b3 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 @@ -141,17 +141,25 @@ Discourse.KeyboardShortcuts = Ember.Object.createWithMixins({ 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 +168,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/stylesheets/common/components/keyboard_shortcuts.css.scss b/app/assets/stylesheets/common/components/keyboard_shortcuts.css.scss index aa93d5fe182..7825a799b5d 100644 --- a/app/assets/stylesheets/common/components/keyboard_shortcuts.css.scss +++ b/app/assets/stylesheets/common/components/keyboard_shortcuts.css.scss @@ -2,7 +2,7 @@ border-left: 1px solid transparent; } -.topic-list-item.selected td:first-child, .topic-post.selected { +#topic-list tr.selected td:first-child, .topic-list-item.selected td:first-child, .topic-post.selected { border-left: 1px solid $danger; }