FIX: J/K navigation resets current selection when scrolling fast.

FIX: J/K navigation resets current selection when scrolling fast.

Sometimes, when keeping J or K pressed and scrolling fast, the current selection would go out of the viewport for a few moments and the algorithm would try selecting the “best” element that is in viewport.

This bug is reproducible only on certain machines. For example, Linux machines seem to be passing key events faster to the browser.

diff --git a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6 b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
index 5e0a399..664a1cb 100644
--- a/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
+++ b/app/assets/javascripts/discourse/lib/keyboard-shortcuts.js.es6
@@ -441,7 +441,7 @@ export default {
 
     // Discard selection if it is not in viewport, so users can combine
     // keyboard shortcuts with mouse scrolling.
-    if ($selected.length !== 0) {
+    if ($selected.length !== 0 && !fast) {
       const offset = minimumOffset();
       const beginScreen = $(window).scrollTop() - offset;
       const endScreen = beginScreen + window.innerHeight + offset;

GitHub sha: df6630f8

3 Likes