A platform for community discussion. Free, open, simple.
FIX: J/K keyboard shortcut misbehaving
Régis Hanol41150fc0cdba
diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6index 766a77e0240..6a1ddbdf9f1 100644--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6@@ -311,9 +311,7 @@ export default {_moveSelection(direction) {const $articles = this._findArticles();- if (typeof $articles === 'undefined') {- return;- }+ if (typeof $articles === 'undefined') return;const $selected = ($articles.filter('.selected').length !== 0)? $articles.filter('.selected')@@ -322,27 +320,15 @@ export default {let index = $articles.index($selected);if ($selected.length !== 0) {- if (direction === -1 && index === 0) { return; }- if (direction === 1 && index === ($articles.length - 1) ) { return; }+ if (direction === -1 && index === 0) return;+ if (direction === 1 && index === $articles.length - 1) return;}- // if nothing is selected go to the first post on screen+ // when nothing is selectedif ($selected.length === 0) {- const scrollTop = $(document).scrollTop();-- index = 0;- $articles.each(function() {- const top = $(this).position().top;- if (top >= scrollTop) {- return false;- }- index += 1;- });-- if (index >= $articles.length) {- index = $articles.length - 1;- }-+ // select the first post with its top visible+ const offset = minimumOffset();+ index = $articles.toArray().findIndex(article => article.getBoundingClientRect().top > offset);direction = 0;}@@ -362,7 +348,11 @@ export default {},_scrollToPost($article) {- $(window).scrollTop($article.offset().top - minimumOffset());+ if ($article.find("#post_1").length > 0) {+ $(window).scrollTop(0);+ } else {+ $(window).scrollTop($article.offset().top - minimumOffset());+ }},_scrollList($article) {@@ -390,14 +380,13 @@ export default {_findArticles() {- const $topicList = $('.topic-list'),- $topicArea = $('.posts-wrapper');+ const $topicList = $(".topic-list");+ const $postsWrapper = $(".posts-wrapper");- if ($topicArea.length > 0) {- return $('.posts-wrapper .topic-post, .topic-list tbody tr');- }- else if ($topicList.length > 0) {- return $topicList.find('.topic-list-item');+ if ($postsWrapper.length > 0) {+ return $(".posts-wrapper .topic-post, .topic-list tbody tr");+ } else if ($topicList.length > 0) {+ return $topicList.find(".topic-list-item");}},