-
Notifications
You must be signed in to change notification settings - Fork 58
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
Splitting Block Before Swiped Word Loses Word #2373
Comments
I can repro at hash c2a85e0, on a physical Pixel 2XL (Android 10). |
I was able to reproduce it on Android (wpandroid alpha-223). |
TL;DR: I think the Aztec library for Android differentiates between swiped and typed text when handling the Enter key event. This bug isn't reproducible in the Classic editor because unlike react-native-aztec, the Classic editor doesn't use custom Enter key handling AFAIK. InvestigationI reproduced this on Android v15.2 in Gutenberg. I don't see this bug in the Classic editor which implies the bug might not be in Aztec itself but in either the Aztec wrapper (react-native-aztec) or in Gutenberg itself (e.g. rich-text). The bug is present in all rich text blocks (Paragraph, Heading, List, Quote, Preformatted, Pull Quote, etc) but not present on the Code and Shortcode block which don't use rich text (and are not powered by Aztec). It's present on blocks that don't split when Enter is tapped (e.g. Quote, Preformatted, Pull Quote, Verse), so this bug isn't related to splitting blocks like I thought previously, but is about how the Enter key event is handled. To reiterate previous comments, it's only present when swiping on the Gboard, not when typing. DebuggingI debugged using the Verse block instead of the Paragraph block because it a) reproduces the bug and b) avoids the unnecessary complexity of blocks being split in the process (tapping Enter in a Verse block just creates a newline within the same block). I put a breakpoint in rich-text's View JSON{ "start": 5, "end": 5, "formats": [ ... ], "replacements": [ ... ], "text": "Hello" <-- missing the " world" portion of the text } I then did the same steps, but instead of swiping I typed the text View JSON{ "start": 6, "end": 6, "formats": [ ... ], "replacements": [ ... ], "text": "Hello world" } Going back to the failing case when swiping, why is The Verse block, like any other that uses rich text, embeds an instance of Aztec. There is a React Native wrapper around this native view, called react-native-aztec. It handles sending events, such as key presses from where they originate inside Aztec to the React Native code, where they can have custom handling. Inside react-native-aztec,
Next stepsI think the key to solving this is to look at Aztec's |
To isolate the problem to Aztec and ensure it's not an issue in react-native-aztec or its usage of Aztec, I modified the Aztec demo project for Android to use a View codepackage org.wordpress.aztec.demo; What I found is that the Enter event only fired when using the default Samsung keyboard of my S10 device, not when using the Google Gboard. These events are added using This StackOverflow answer points to the
The suggested answer is to use a Edit: text watchers are used in react-native-aztec here, so digging there could lead to a fix. |
Could the bug you're seeing be specific to lists? If so, it could be #2204. |
You're right. 👍 I forgot that #2204 involved more than just the multiple undo states, but also touched on loss of content with the initial split. |
I think this ticket is not actually worked on at the moment so, I'll remove the assignee to denote that. @cameronvoell , if you have any particular progress you want to add to the ticket for context, that'd be helpful for when we'll pick this up again. Thanks! |
FYI: Still an issue as of screencapture-1626115972173.mp4 |
I picked up this issue for Groundskeeping and did a bunch of debugging but haven't found a resolution yet. It’s an issue that only seems to happen when swiping out words using Gboard. It doesn’t happen when swiping words out on the Swiftkey keyboard, or tapping words out on any of the keyboards I’ve tested including Gboard. I spent hours debugging different areas of the app by adding logging, stepping through code in the Chrome debugger and in Android Studio trying desperately to figure out where in the code we were erroneously handling something but I had no luck. Here is some of my logging to demonstrate what I mean. The logs are from two different places: Android Logcat and console logging for the React-based code: Android logs
React logs
The word "two" is removed from the string before the I did a bunch of searches online and found a post describing the same behavior while porting a React-based editor library called Slate to be used on Android using React Native. Here’s a little snippet from the post: It feels like step #5 in this snippet doesn’t happen for us since that erroneously deleted text doesn’t get added back visually, but if you look at the Android logs I posted above, you do see it get added back:
And there is an event sent with the correct string afterword, but it seems to die at that point, possibly due to a race condition:
The author went on to note that he has not found a good workaround and feels something needs to be fixed in the syncing of selection. I’m throwing in the towel on this issue for the moment to work on other Groundskeeping issues but wanted to document what I learned during this for future reference. Maybe someone who understands Aztec’s integration with React Native will read this and have an “aha” moment that leads to a fix 🤞 |
FWIW, issue doesn't happen to me if I manually press SPACE between the swiped words. |
I continued the investigations on this issue (thanks @AmandaRiu for such detailed debugging, it really helped me out on getting easily the context 🙇 !). In this case, I decided to explore and debug the native side and Aztec-Android , as the React Native side was already covered in previous comments. As mentioned previously, when swiping out words using Gboard, splitting words produces an odd behavior leading to some of the words being deleted. For the debug test, I relied on the Here are the results when pressing the enter key after swiping out words
As far as I checked, the issue is related to the way we detect when the intro key has been pressed (step 3) and notify the React Native side before step 4 is executed. If we manage to figure out a way to trigger the |
Yep, I experienced the same behavior. I debugged both cases and the main difference is that when adding words by swiping, Android calls the method |
I tried to figure out a way to address this issue but no luck so far. I'd like to leave here some notes in case we revisit it in the future: Gboard changes the text in multiple stepsI tested the Gboard on other apps and I noticed that the words added by swiping are treated as a single item when being modified. For example, when pressing the backspace key, instead of deleting one character it deletes the entire word. Similarly, when pressing enter, between words (this behavior is the one related to this issue) it breaks the text into two lines but also removes the blank space introduced when the word was added.
The interesting part about the latter (the new line between words), as described in previous comments, is that instead of modifying the text in one change, it's being done in five actions.
I couldn't find the source code of the Gboard app to know the cause of executing so many steps. One thing I noticed is that this issue doesn't happen if after adding words, another text input is focused and then the text input is focused again. Looks like Gboard only gives words a special treatment while the text input is focused. Potential workaroundsPrevent Gboard call
|
This issue is no longer happening in the latest Before closing the issue, @fluiddot I was wondering if you could double-check on your device as you have previously investigated this thoroughly. For now, I'll remove the High priority label, thank you! |
Thanks for taking a look @geriux 🙇 ! I confirmed that the issue can't be reproduced in version android-gboard-split-words.mp4 |
Thanks for checking it!
Cool! I agree 🚀 |
Describe the bug
On Android, splitting a paragraph block with the cursor immediately before a swiped word causes that word to be lost.
To Reproduce
Expected behavior
Splitting a block should never lose content.
Smartphone
The text was updated successfully, but these errors were encountered: