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

Writing Flow: Caret position not always preserved in vertical traversal #15604

Closed
aduth opened this issue May 13, 2019 · 2 comments
Closed

Writing Flow: Caret position not always preserved in vertical traversal #15604

aduth opened this issue May 13, 2019 · 2 comments
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release

Comments

@aduth
Copy link
Member

aduth commented May 13, 2019

Describe the bug

When vertically navigating between paragraphs using ArrowUp, ArrowDown, the caret does not always land where would be expected to preserve its horizontal position.

It seems to be impacted by the field "remembering" where the caret was when last focused, rather than where it should be.

To reproduce

Steps to reproduce the behavior:

  1. Navigate to Posts > Add New
  2. Click the writing prompt
  3. Add a paragraph of text "abc"
  4. Press Enter
  5. Add a paragraph of text "123"
  6. Press ArrowUp
  7. Press ArrowLeft 3 times
  8. Press ArrowDown
  9. Note that the caret is placed at the end of the second paragraph

Expected behavior

The caret should be placed at roughly equivalent horizontal offset as where it originated from in the first paragraph (i.e. at the start of the paragraph).

Screenshots

h-position

Desktop:

  • OS: macOS 10.14.4 (18E226)
  • Browser: Chrome Version 74.0.3729.131
@aduth aduth added [Type] Bug An existing feature does not function as intended [Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Regression Related to a regression in the latest release labels May 13, 2019
@aduth
Copy link
Member Author

aduth commented May 13, 2019

The result of some initial debugging:

The underlying cause of the issue is that we set verticalRect only when unset, and only clear it when either clicking within the WritingFlow area, or when WritingFlow handles horizontal navigation.

if ( ! isVertical ) {
this.verticalRect = null;
} else if ( ! this.verticalRect ) {
this.verticalRect = computeCaretRect();
}

onMouseDown={ this.clearVerticalRect }

This has been the behavior since its original introduction in #2988.

I expect this regressed as an indirect result of #13697 (change), specifically that RichText calls to Event#preventDefault in its own handling of horizontal arrow navigation:

// In all other cases, prevent default behaviour.
event.preventDefault();

Since WritingFlow respects defaultPrevented, the logic to unset verticalRect for horizontal navigation will not be reached.

// Abort if navigation has already been handled (e.g. RichText inline
// boundaries).
if ( event.nativeEvent.defaultPrevented ) {
return;
}

When the next vertical traversal occurs then, it uses the old, inaccurate verticalRect value, since it was never unset in the interim.

placeCaretAtVerticalEdge( closestTabbable, isReverse, this.verticalRect );

Proposed solution:

It's not clear to me that we even need verticalRect to be an instance variable, vs. computed on-demand at the logic above for placeCaretAtVerticalRect. Doing so appears to resolve the issue in some brief testing.

Based on the onMouseDown reset behavior, it may have been partly necessary for either multi-selection or non-collapsed selections? The mouse dependency is concerning nonetheless, and existing writing-flow.test.js end-to-end tests pass without the instance variable (which would indicate we need better tests if the instance variable is necessary).

cc @ellatrix

@aduth
Copy link
Member Author

aduth commented May 15, 2019

Fixed by #15624 (an alternative to #15607).

@aduth aduth closed this as completed May 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Writing Flow Block selection, navigation, splitting, merging, deletion... [Type] Bug An existing feature does not function as intended [Type] Regression Related to a regression in the latest release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant