Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved arrow navigation #2296

Closed
wants to merge 4 commits into from
Closed

Improved arrow navigation #2296

wants to merge 4 commits into from

Conversation

ellatrix
Copy link
Member

@ellatrix ellatrix commented Aug 8, 2017

This PR changes arrow navigation so that the vertical position is preserved. Still a WIP, but feel free to play with it.

To do:

  • Add editable left/right nav.
  • Handle scroll properly.
  • Look into editables with padding.
  • Preserve second last line x position if the last line is shorter.

@ellatrix ellatrix added [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Status] In Progress Tracking issues with work in progress labels Aug 8, 2017
@ellatrix ellatrix added this to the Beta 0.8.0 milestone Aug 8, 2017
@ellatrix ellatrix self-assigned this Aug 8, 2017
@mattyrob
Copy link

mattyrob commented Aug 9, 2017

I've been directed here from the WordPress.org forums. Just to point out that arrow cursor navigation is broken on Safari in Gutenberg 0.7.0 and buggy in FF and Chrome on MacOS also.

Basically arrow navigation only works inside a single block in Safari.

In FF, Up and down navigate only within a block, at the start or ned, left or right move the highly to the next block and then you are navigating by block. If you end up in the Title block though arrow navigation stops working.

In Chrome, up and down navigation works but when you are at the top of one block, hitting up takes you to the top of the block above - not the end - so different to FF. Again, if you end up in the Title block though arrow navigation stops working.

followingEditor.selection.collapse( false );
}
} else {
window.setTimeout( () => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here again I'm not sure why exactly it doesn't work without the timeout... @spocke or anyone @tinymce, any idea why?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should get rid of this, because it also prevents the positioning if you hold the arrow key.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, editor.selection.placeCaretAt doesn't seem to work in Firefox, even though it should support https://developer.mozilla.org/en-US/docs/Web/API/Document/caretPositionFromPoint.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it does work with caretRangeFromPoint... FF supports both, and Chrome and Safari will fall back to that one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, so in Firefox it works without a timeout and without focussing first (but we still need to move the focus...) and in Chrome and Safari in doesn't work without focussing first and the timeout. 😖

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spocke For me that doesn't seem to work. When focus is called it will move to it to the last range when there was focus.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Chrome and Safari, it will work moving down, but not up. In Firefox it still won't work at all.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't seem to reproduce that for me the fiddle works on Mac, Windows, Linux various versions of Chrome since I use the dev channel on my dev machine and stable on the windows testing machine.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sure you bind that even early since otherwise handlers inside tinymce might want to act on the down key as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just can't get it to work in Gutenberg. To me it seems weird that we'd have to execute that twice anyway. That suggests that it somehow doesn't work correctly.

@ellatrix
Copy link
Member Author

This should work already nicely now, albeit with a lot of code... One thing I don't like is how this introduces so much code to this component that feels like it should belong to Editable. @youknowriad do you think I should try the props again? Not sure how to better handle this as what I have now.

@codecov
Copy link

codecov bot commented Aug 10, 2017

Codecov Report

Merging #2296 into master will decrease coverage by 0.31%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2296      +/-   ##
==========================================
- Coverage    25.9%   25.58%   -0.32%     
==========================================
  Files         157      157              
  Lines        4853     4921      +68     
  Branches      822      848      +26     
==========================================
+ Hits         1257     1259       +2     
- Misses       3035     3077      +42     
- Partials      561      585      +24
Impacted Files Coverage Δ
editor/modes/visual-editor/block.js 0% <0%> (ø) ⬆️
blocks/color-palette/index.js 0% <0%> (ø) ⬆️
blocks/library/cover-text/index.js 36% <0%> (+1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 77620b2...33557b3. Read the comment docs.

@ellatrix
Copy link
Member Author

Merging #2296 into master will increase coverage by 2.8%.

@nylen Huh, why would this increase coverage? :)

@nylen
Copy link
Member

nylen commented Aug 10, 2017

I'm not sure why, but Codecov has the wrong base commit for this PR:

Let's try this allow_coverage_offset setting from https://docs.codecov.io/v4.3.6/docs/comparing-commits#section-resolution (cbcb14d).

@ellatrix
Copy link
Member Author

@aduth Do you think I should the EditableProvider for this similarly to your focus PR?

@nylen
Copy link
Member

nylen commented Aug 10, 2017

I pushed 2 other branches to try to track down the coverage issue:

  • try/improved-arrow-nav-original - this PR with a minor change to trigger a full rebuild. The Codecov build failed saying "Missing base report. Unable to compare commits because the base of the compare did not upload a coverage report." which I think is better than reporting incorrect results.
  • try/improved-arrow-nav-rebased - this PR rebased against master. Coverage appears to be reported correctly.

The base commit of this PR should be d7033d5 which appears to have a passing Codecov build. However, in the list of builds for master, the commit hash for that commit is wrong, and the previous commit still says "Processing reports" after a couple days:

2017-08-10t14 39 16-0500

I am not entirely sure what happened but I would suggest that we rebase this PR and separately add that codecov.yml setting (#2354).

Copy link
Member

@aduth aduth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my testing, this feels very nice, and I think is a good step toward restoring some simple text interactions if we're going to keep with the Editable-per-paragraph direction.

One interaction that doesn't work quite as well as in most native editors is remembering the original caret position even when navigating across an empty block or a block with shorter content.

Expected:

arrow-memory

Actual:

arrow-memory-actual

@aduth Do you think I should the EditableProvider for this similarly to your focus PR?

Not sure what you have in mind here specifically, but there is a fair amount of complexity here, and it is not very well isolated. Maybe using the EditableProvider could be used here to surface up and isolate the handling. Specifically to try to remedy:

  • The individual block querying all adjacent blocks in the DOM
  • Blocks being bound to TinyMCE as the only supported arrow navigation (maybe this ought to be conceded)

Generally this could use some more comments, as some of the logic is quite dense and not self-evident.


const isVerticalEdge = ( { editor, reverse } ) => {
const rangeRect = editor.selection.getBoundingClientRect();
const buffer = rangeRect.height / 2;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this buffer for, and how did you come to arrive at rangeRect.height / 2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than trying to place the caret at the very top or bottom (which might be off by 0-1px), it seems better to attempt to place it in the middle of the line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I'll comment)

} else {
window.setTimeout( () => {
const buffer = rect.height / 2;
const editorRect = followingEditor.getBody().getBoundingClientRect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know followingEditor still exists after this setTimeout ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know you commented previously something similar. In this case I want to get right of the timeout as it doesn't work in Firefox, and it breaks holding the arrow key.

@ellatrix
Copy link
Member Author

One interaction that doesn't work quite as well as in most native editors is remembering the original caret position even when navigating across an empty block or a block with shorter content.

I will fix that. We can remember the first position, and discard it when you press any other key.

@ellatrix
Copy link
Member Author

@aduth Okay, I fixed that for the down key. For the up key it's harder as we don't manage the position after the last line. We only set it when moving the caret from one editor to another. If we want to fix that we should manage up and down fully... :/

@ellatrix
Copy link
Member Author

(Or at least the first, second last, and last line.)

@mtias mtias modified the milestones: 0.10.0, Beta 0.9.0 Aug 18, 2017
@karmatosed karmatosed modified the milestones: 0.11.0, 0.10.0 Aug 25, 2017
@karmatosed karmatosed closed this Aug 30, 2017
@ntwb ntwb deleted the try/improved-arrow-nav branch September 4, 2017 08:03
@ellatrix
Copy link
Member Author

Hm, not sure why this PR was closed... I'll rebase in a new one.

@ellatrix ellatrix restored the try/improved-arrow-nav branch October 10, 2017 20:10
@ellatrix ellatrix reopened this Oct 10, 2017
@ellatrix ellatrix mentioned this pull request Oct 11, 2017
3 tasks
@ellatrix
Copy link
Member Author

Opening a new PR.

@ellatrix ellatrix closed this Oct 11, 2017
@ellatrix ellatrix deleted the try/improved-arrow-nav branch October 11, 2017 13:37
@ellatrix ellatrix mentioned this pull request Oct 11, 2017
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). [Status] In Progress Tracking issues with work in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants