You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Writing Flow: Caret position not always preserved in vertical traversal #15604
[Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release
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:
Navigate to Posts > Add New
Click the writing prompt
Add a paragraph of text "abc"
Press Enter
Add a paragraph of text "123"
Press ArrowUp
Press ArrowLeft 3 times
Press ArrowDown
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).
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.
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:
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).
[Feature] Writing FlowBlock selection, navigation, splitting, merging, deletion...[Type] BugAn existing feature does not function as intended[Type] RegressionRelated to a regression in the latest release
Activity
aduth commentedon May 13, 2019
The result of some initial debugging:
The underlying cause of the issue is that we set
verticalRectonly when unset, and only clear it when either clicking within the WritingFlow area, or whenWritingFlowhandles horizontal navigation.gutenberg/packages/block-editor/src/components/writing-flow/index.js
Lines 284 to 288 in 449c254
gutenberg/packages/block-editor/src/components/writing-flow/index.js
Line 348 in 449c254
This has been the behavior since its original introduction in #2988.
I expect this regressed as an indirect result of #13697 (change), specifically that
RichTextcalls toEvent#preventDefaultin its own handling of horizontal arrow navigation:gutenberg/packages/block-editor/src/components/rich-text/index.js
Lines 769 to 770 in 449c254
Since
WritingFlowrespectsdefaultPrevented, the logic to unsetverticalRectfor horizontal navigation will not be reached.gutenberg/packages/block-editor/src/components/writing-flow/index.js
Lines 272 to 276 in 449c254
When the next vertical traversal occurs then, it uses the old, inaccurate
verticalRectvalue, since it was never unset in the interim.gutenberg/packages/block-editor/src/components/writing-flow/index.js
Line 316 in 449c254
Proposed solution:
It's not clear to me that we even need
verticalRectto be an instance variable, vs. computed on-demand at the logic above forplaceCaretAtVerticalRect. Doing so appears to resolve the issue in some brief testing.Based on the
onMouseDownreset behavior, it may have been partly necessary for either multi-selection or non-collapsed selections? The mouse dependency is concerning nonetheless, and existingwriting-flow.test.jsend-to-end tests pass without the instance variable (which would indicate we need better tests if the instance variable is necessary).cc @ellatrix
aduth commentedon May 15, 2019
Fixed by #15624 (an alternative to #15607).