FIX: Fallback to last post when the in-view post cannot be detected.

FIX: Fallback to last post when the in-view post cannot be detected.

In certain situations the detection method fails. For example, it fails for a topic containing: a long post (~1600px height), gap, small action (focus on this), hidden reply.

diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
index 97817f8..000cc33 100644
--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
@@ -445,6 +445,9 @@ export default {
       $selected = $articles
         .toArray()
         .find(article => article.getBoundingClientRect().top > offset);
+      if (!$selected) {
+        $selected = $articles[$articles.length - 1];
+      }
       direction = 0;
     }

GitHub sha: 7a7c6af2

1 Like

article.getBoundingClientRect().top may be a negative value (e.g. -2000) which made the predicate used for find always false.

This commit has been mentioned on Discourse Meta. There might be relevant details there: