mirror of
https://github.com/discourse/discourse.git
synced 2025-01-19 17:02:45 +08:00
UX: Discard selected post if it is not in viewport. (#7869)
This way, users can combine keyboard shortcuts with mouse scrolling.
This commit is contained in:
parent
8b2580e20f
commit
90fcdad3cd
|
@ -439,9 +439,22 @@ export default {
|
||||||
$selected = $articles.filter("[data-islastviewedtopic=true]");
|
$selected = $articles.filter("[data-islastviewedtopic=true]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Discard selection if it is not in viewport, so users can combine
|
||||||
|
// keyboard shortcuts with mouse scrolling.
|
||||||
|
if ($selected.length !== 0) {
|
||||||
|
const offset = minimumOffset();
|
||||||
|
const beginScreen = $(window).scrollTop() - offset;
|
||||||
|
const endScreen = beginScreen + window.innerHeight + offset;
|
||||||
|
const beginArticle = $selected.offset().top;
|
||||||
|
const endArticle = $selected.offset().top + $selected.height();
|
||||||
|
if (beginScreen > endArticle || beginArticle > endScreen) {
|
||||||
|
$selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If still nothing is selected, select the first post that is
|
// If still nothing is selected, select the first post that is
|
||||||
// visible and cancel move operation.
|
// visible and cancel move operation.
|
||||||
if ($selected.length === 0) {
|
if (!$selected || $selected.length === 0) {
|
||||||
const offset = minimumOffset();
|
const offset = minimumOffset();
|
||||||
$selected = $articles
|
$selected = $articles
|
||||||
.toArray()
|
.toArray()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user