gutenberg icon indicating copy to clipboard operation
gutenberg copied to clipboard

Block navigation doesn't work when arrow keys are held down

Open ephox-mogran opened this issue 9 years ago • 7 comments

Issue Overview

When holding down the UP or DOWN keys, the cursor does not move to the next block once it hits the boundary of that block. It does navigate to the next block as soon as you release the arrow key, however. This is because the arrow key navigation is bound to keyup instead of keydown.

Steps to Reproduce (for bugs)

  1. Create a page with several blocks
  2. Focus the first block
  3. Hold down the arrow key (for five seconds)

Expected Behavior

The cursor should move down the blocks

Current Behavior

The cursor stays in the same spot, until the key is released. Then, it moves by one block

Possible Solution

Allow keydown to navigate between blocks.

ephox-mogran avatar Oct 11 '17 07:10 ephox-mogran

I can see two ways of doing this

  1. Eliminate keyup altogether in writing-flow. This means we won't have the preventDefault, which may be a problem (not sure what it was there for). This also gets rid of the shouldMove state entirely.
  2. Keep keyup, but make keydown have an alternate if condition that says firstly if shouldMove is already true (so keydown occurred first without a keyup), then move like keyup does. This keeps the keyup handling, but means that holding keydown keeps navigating after the first one fires as long as the user has the key held down.

I'll setup a PR with (1) because the code is cleaner, but if that's a problem, we can look at doing (2).

ephox-mogran avatar Oct 11 '17 07:10 ephox-mogran

Note, we'll probably also have to define what Shift + Up and Shift + Down should do. My preference would be that they would allow the same multi-block selection that mouse does.

ephox-mogran avatar Oct 11 '17 07:10 ephox-mogran

There's a reason arrow navigation is using onKeyUp instead of onKeyDown https://github.com/WordPress/gutenberg/pull/2894#issuecomment-334690488

Maybe it's fixable though with some exploration.

youknowriad avatar Oct 11 '17 08:10 youknowriad

So basically the keyup was firing an extra move afterwards? So then would it be possible to make the keydown still the thing that moves the block, and just make keyup prevent default if shouldMove is true?

ephox-mogran avatar Oct 11 '17 09:10 ephox-mogran

Or did

causing the caret to move unexpectedly

not mean that it was doing an exra move in the right direction, but that it was doing some random move?

ephox-mogran avatar Oct 11 '17 09:10 ephox-mogran

Yes, it was doing that and I tried preventing back then with no success. But this extra move is not happening in my last testing

youknowriad avatar Oct 11 '17 09:10 youknowriad

Fixed by #2979.

ellatrix avatar Oct 11 '17 21:10 ellatrix