Keyboard shortcut J/K(Next/Previous) continues key down cause screen flickering and scroll jerkiness

keyboard

(lid) #1

1.open a topic with multiple posts

2.press the key J down it will start moving to next item repeatedly.Until there are no more items it will stop at the bottom of the page

at this point you should see that the scrolling and scroll bar is unstable, scroll bar jumps and change sizes.

You can repeat the process from the last item back to the top first item
3.press the key K down it will start moving to previous item, until there are no more items it will stop at the top

Tested on: Chrome, Firefox / Win


Keyboard shortcut Next/Previous continues key down reset to first item in list on load more
(TechnoBear) #2

Is that not the same issue reported here:


(lid) #3

Not particularly the same issue.

J/K technically should not be “rate limited”. @cpradio also excluded them from the PR he sent and linked in the discussion.

https://github.com/discourse/discourse/pull/2757


(TechnoBear) #4

I’m not seeing the issue you describe (Firefox 32 on Ubuntu). In general use, I wouldn’t press and hold j/k; I’d use Home, End or # to move quickly through the topic. However, I’ve just tried both here and on our own instance and can’t reproduce your results.

Edit: Until immediately after I posted that, then it occurred - but it’s not consistent.


(lid) #5

I have tested on chrome and firefox on Windows platform
And it is pretty consistent on chrome. up or down


(Rikki Tooley) #6

It is the same issue… the solution to this would be to prevent multiple keypress callbacks from running at the same time using rate limiting.


(lid) #7

It is related issue but not the same issue. and it is possible that fixing one will fix the other.
However the solution suggested for the other topic is not the solution for J/K navigation in a topic view.
moving over multiple items on one keydown should be smooth and snappy.

Artificial Throttling of the keydown event could solve or improve the reported behavior

Additionally The topic list view does not suffer from this issue and I don’t think there is any rate limit there.


(cpradio) #8

@codinghorror, can we merge these topics? (see @TechnoBear’s post)

I want to resolve these together, but need to approach it from a different direction.


(Kane York) #9

Not quite… the bug seems to be that LockOn.js is buggy & overshoots the scroll, repeatedly. It stops when by some race condition it comes up with the right number.

:confused:


(cpradio) #10

Huh? I know mousetrap.js is being used, but what is LockOn.js? and where is that being used?


(Kane York) #11

Interestingly, in only 1 spot now.

assets/javascripts/discourse/lib/url.js

  /**
    Jumps to a particular post in the stream
  **/
  jumpToPost: function(postNumber) {
    var holderId = '#post-cloak-' + postNumber;

    Em.run.schedule('afterRender', function() {
      if (postNumber === 1) {
        $(window).scrollTop(0);
        return;
      }

      new LockOn(holderId, {offsetCalculator: function() {
        var $header = $('header'),
            $title = $('#topic-title'),
            windowHeight = $(window).height() - $title.height(),
            expectedOffset = $title.height() - $header.find('.contents').height() + (windowHeight / 5);

        return $header.outerHeight(true) + ((expectedOffset < 0) ? 0 : expectedOffset);
      }}).lock();
    });
  },

(cpradio) #12

And that doesn’t pertain to the _moveSelection that the keyboard shortcuts use right? At least I don’t see the connection…


(Kane York) #13

Try following the call chain - I’m pretty sure it calls jumpToPost at some point. Ctrl-B in any JetBrains ide should do it.


(cpradio) #14

Ah, okay, it does. But only under a certain condition. I still think it is related to the other thread though. As it only happens because the keys are throttled. Once that happens, it will cease to move down the list when holding key down and make it a better overall experience.

Though I don’t understand the “screen flicking/jerkiness” part, when I hold the j key down I don’t get jerkiness, I just it scrolling down just fine and then when it loads more topics, it shoots to the top again (different issue). So maybe I don’t understand the whole problem here.


(Sam Saffron) #15

I fixed this a while back, works fine now.


(Sam Saffron) #16