-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
After two blocks are merged, show cursor on the end of the text field #14820
After two blocks are merged, show cursor on the end of the text field #14820
Conversation
…k-moves-cursor-to-last-location-in-previous-block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @marecar3 - Nice job moving the caret logic to JS 🎉
As I understand, we are basically moving the caret at the end if the block has been selected but RichText hasn't been set to focus yet. This happens when the block using RichText has been selected programmatically instead of by the user tapping on RichText.
This works well since when the user tap on RichText
directly, onFocus
is triggered first, setting isTouched to true and keeping the caret where the user tapped. But when the system set the focus, componentWillReceiveProps
is called first, and then onFocus
, moving the caret at the end.
This also work with BottomSheet since when it is dismissed, onFocus is also triggered first.
Please let me know if I'm wrong :)
I tried to find other instances where we set focus programmatically where this might be a problem, and I found a small corner case:
When we delete a block, the previous block is automatically selected in a similar way than when merging blocks, so in this case the caret is also moved to the end. I don't think this a big issue and it might be even expected? I'm not sure 🤔
I wonder if this logic might also be a problem in future features.
I did found a small bug in the logic:
When we merge into a block that hasn't been selected yet, the caret is still at the beginning. I added a code comment where I think is the problem.
I miss some comments to clarify what's happening. Maybe to encapsulate the logic inside componentWillReceiveProps
into a helper function moveCaretToTheEndIfNeeded()
(or similar explanatory name) would help.
// This logic will handle the selection when two blocks are merged or when block is split | ||
// into two blocks | ||
if ( nextTextContent === this.savedContent || nextTextContent.startsWith( this.savedContent ) ) { | ||
this.forceSelectionUpdate( this.savedContent.length, this.savedContent.length ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When the block haven't been selected yet, this.savedContent
is empty. So this won't move move the caret at the end.
Maybe we can set the real savedContent
value on constructor()
instead of an empty string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good catch here @etoledom , managed to reproduce by starting a draft adding 2 paragraphs then exiting the editor and opening again, then deleting text from the second paragraph
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @etoledom, the good catch here. I have fixed the problem but in another way as when I did like you suggest It showed another issue.
…k-moves-cursor-to-last-location-in-previous-block
Fixed bug with positioning caret on the start of text when merging two blocks if first has never been selected in the past
Hey, @etoledom thanks for the good review! You have found some good bugs here :)
I have seen similar behavior on Gutenberg web, so I guess it's ok to have it same?
I think I have fixed that bug now, so you can give it a try. |
On Android emulator, I'm encountering an issue where I can't merge blocks with backspace. To reproduce:
Expected result: Two paragraph blocks are merged back together. Actual result: Nothing seems to happen. Here is a screenshot: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @marecar3 for the updates!
I have seen similar behavior on Gutenberg web, so I guess it's ok to have it same?
I agree ✅
I think I have fixed that bug now, so you can give it a try.
Fixed 🎉
Looks good on iOS!
Let's keep this solution. Hopefully in the future we can have a dispatch action (or similar) to adjust selection from other than just within RichText.
…k-moves-cursor-to-last-location-in-previous-block
Hey @mkevins nice one!!! :) |
I just tested it out and the Android emulator, and it looks like your latest patch fixed the issue I was encountering! 🎉 Screenshot: In the process of testing, I encountered a different issue, but it's not related to this PR. I have opened an issue to track it: wordpress-mobile/gutenberg-mobile#851 . Thanks @marecar3 ! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @marecar3 👋 . I just have a few comments I was hoping you could help me with to better understand the changes.
Hey @mkevins, I have left the answers. Let me know if they are clear or if you have some other questions. |
Thanks @marecar3 for clarifying those points. Your explanation is very helpful! |
…WordPress#14820) After two blocks are merged, show cursor on the end of the text field
I'm a bit confused by the new |
Hey @hypest, your suggestion is on the place, we can do it. |
Hey @marecar3, a dedicated PR would be better to track, review and merge 👍 |
Fixes : wordpress-mobile/gutenberg-mobile#699
Support for gutenberg-mobile PR : wordpress-mobile/gutenberg-mobile#756