mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:24:05 -06:00
FIX: J/K keyboard shortcut misbehaving
This commit is contained in:
parent
62aacce8f4
commit
41150fc0cd
@ -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 selected
|
||||
if ($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) {
|
||||
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");
|
||||
}
|
||||
},
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user