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

After two blocks are merged, show cursor on the end of the text field #756

Conversation

marecar3
Copy link
Contributor

@marecar3 marecar3 commented Mar 18, 2019

Based on issue: #699

Corresponding gutenberg PR : WordPress/gutenberg#14820

There are two issues :

Issue A: After two blocks are merged, a cursor will be placed on the last remembered position in the block. (Affected both iOS and Android platform)

Steps to reproduce:

  1. Create a new Gutenberg post with 2 simple paragraph blocks
  2. Put the cursor somewhere in the first block except its end
  3. Go to the end of the second block and start backspacing to delete characters. Delete up until the very first character of the second block
  4. Notice that the "Start writing" placeholder text appears
  5. Notice the caret is placed at the position set in step 2

Issue B: When the user clears the text in the e.g. Paragraph/Heading block, a block will be merged right after the last letter is deleted. (Affects only Android platform) - Which should be a case, as on iOS block will be merged after one extra backspace.

Steps to reproduce:

  1. Create a new Gutenberg post with 2 simple paragraph blocks
  2. Go to the end of the second block and start backspacing to delete characters. Delete up until the very first character of the second block
  3. Notice that the "Start writing" placeholder text appears
  4. After a small delay the focus moves to the first block. Sometimes the whole second block gets removed, some time is stays there. This step only happens on Android. On iOS, you need to backspace once more to cause the block merge.

Hey @daniloercoli , @mzorz at this point I invested some extra time and I couldn't find a better solution so I am very open to hearing your suggestions if you have something on your mind. I tried to find some common solution which would be placed in JS code, but it seems that it couldn't be doable from JS side. I will mark this one as ready for review very soon so that you can start reviewing it.

… avoid block merging when placeholder is present

Move cursor to the end of the text when two blocks being merged
@marecar3 marecar3 self-assigned this Mar 18, 2019
@marecar3 marecar3 changed the title Send backspace event only when it's clicked second time After two blocks are merged, show cursor on the end of the text field Mar 18, 2019
@daniloercoli
Copy link
Contributor

For the Issue A wondering if we can expand the code added here https://github.com/wordpress-mobile/gutenberg-mobile/pull/629/files#diff-5693404c4c8f8d757cd298cc5aabc561R117 introduced to set the caret at the end of text when getting the focus.

…ves-cursor-to-last-location-in-previous-block

# Conflicts:
#	react-native-aztec/android/src/main/java/org/wordpress/mobile/ReactNativeAztec/ReactAztecManager.java
@marecar3
Copy link
Contributor Author

Hey @daniloercoli , thanks for the good point. Please take a look at new iteration :)

@mzorz
Copy link
Contributor

mzorz commented Mar 20, 2019

Hi! I've been looking into this for a while, results of my tests here:

ISSUE B:

  1. start a draft, place 2 paragraph blocks with some text
  2. place cursor at first block
  3. place cursor at end of second block
  4. press and hold BACKSPACE, it will repeat backspace and delete each character rapidly
  5. observe it stops when there's nothing else to delete so, issue described in Deleting all contents of block moves cursor to last location in previous block #699 is ok with this new PR 👍

ISSUE A

This one is still happening for me.
I started debugging the onTakeFocus() method in ReactAztecArrowKeyMovementMethod class, and I realize that when you press backspace for the second time, if (view.getLayout() == null) returns true, so it gets into that code path. Even so though, that code path tells the EditText to place the cursor at the beginning, but it doesn't work (or it does and then somehow we're placing the cursor back again where it originally was? IDK).
So 2 issues here, one is the layout being null (1), the other one about the selection not catching up correctly (2).

  • Re: (1): back to the Android docs, the docs say this https://developer.android.com/reference/android/widget/TextView.html#getLayout()
    Furthermore, checked where the original code was introduced, it's this commit here 538fb9c#diff-5693404c4c8f8d757cd298cc5aabc561
    and the code is taken from the original Android source code, except that it doesn't tell the TextView to place the selection at the beginning but rather at the end of text. IDK if getting a null here is in fact an issue itself but, wondering about the comment in the original source code where it states that it shouldn't be null. I think this one can probably be left as is as there doesn't seem to have visible harm, but stating it here in case there's some relationship to other things going on at the same time.

  • Re: (2) I'm investigating this now, and it seems that setSelection() when the focus changes gets called for the "last" position of the focus and even the last time it gets called is the one in ReactAztecArrowKeyMovementMethod as expected, but still the EditText shows otherwise. That was my first attempt as I thought maybe we're re-setting it from the outside, but doesn't seem to be the case. I'll try now seeing if we need to refresh the view somehow. Just wanted to give the heads up I'm trying to look further and make sense.

Question, does this (2) happen for you @marecar3 ? I'm using a Pixel 2 with Android 8.1 to test.

@mzorz
Copy link
Contributor

mzorz commented Mar 20, 2019

Added PR (comparing branch against this one) to try and fix (2) above here #765

…ification-on-end

Added a minimal delay to call setSelection() to enforce special focus handling cases
@marecar3
Copy link
Contributor Author

marecar3 commented Mar 21, 2019

Hey @mzorz, I have noticed that we introduced some regression, this is the scenario :

  1. Create some paragraph with text
  2. Put the cursor in the middle of the text
  3. Press enter to break the text
  4. The new block is created

Result -> On the newly created block cursor is at the end of the text
Expected -> Cursor should be at the beginning of the text

@mzorz
Copy link
Contributor

mzorz commented Mar 21, 2019

Result -> On the newly created block cursor is at the end of the text
Expected -> Cursor should be at the beginning of the text

🤔 maybe is it due to this change here? https://github.com/wordpress-mobile/gutenberg-mobile/pull/765/files#diff-6d32b8ead802ea7e00caa5563c2239c3L33

@mzorz
Copy link
Contributor

mzorz commented Mar 22, 2019

Just a FYI I was trying something here #773, still need to work more on it but open to any suggestions

@marecar3
Copy link
Contributor Author

Hey @mzorz, thanks for heads up. Will look at it and I am also trying some ideas.

…ves-cursor-to-last-location-in-previous-block
@marecar3
Copy link
Contributor Author

marecar3 commented Apr 4, 2019

Hey Hey @etoledom @mzorz @daniloercoli @pinarol, I have moved the logic to the JS side so if you have time please take a look at this PR and corresponding gutenberg PR : WordPress/gutenberg#14820

Copy link
Contributor

@mzorz mzorz left a comment

Choose a reason for hiding this comment

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

Tested, code LGTM! Thanks for this @marecar3
Feel free to merge after resolving conflicts
:shipit:

@marecar3 marecar3 added this to the v1.3 milestone Apr 10, 2019
@marecar3
Copy link
Contributor Author

Will merge this one as it seems that the same tests are also failing on the develop branch.
cc : @JavonDavis @hypest

@marecar3 marecar3 merged commit f0fe4a4 into develop Apr 10, 2019
@marecar3 marecar3 deleted the fix/699_Deleting-all-contents-of-block-moves-cursor-to-last-location-in-previous-block branch April 10, 2019 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants