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

[BUG] Cursor position after backspace at start of paragraph (android) #544

Open
jwbrown opened this issue Oct 12, 2024 · 4 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@jwbrown
Copy link

jwbrown commented Oct 12, 2024

Describe the bug
On the Pixel 6 pro Android device (Android 14) the cursor is misplaced one character to the right when deleting from the start of a paragraph

To Reproduce
On an android device
Create a document with 2 lines separated by a new line
Line 1
Line 2
Position the cursor to the left of the L in "Line 2"
Press backspace
The new line is removed, but the cursor is positioned to the right of the L for Line 2 rather than between the '1' and the 'L' as it should be.

Expected behavior
I would expect that the cursor would be after the 1 and prior to the L

Device:
Pixel 6 Pro Android

Additional context
The problem does not reproduce on iOS

@jwbrown jwbrown added the bug Something isn't working label Oct 12, 2024
@rambozzang
Copy link

You can use hint and initalText together as shown below.

htmlEditorOptions: const HtmlEditorOptions(
hint: 'Please enter something',
initialText: '',
shouldEnsureVisible: true,
autoAdjustHeight: false,
),

@jwbrown
Copy link
Author

jwbrown commented Oct 15, 2024

Thanks for your reply @rambozzang.

I'm not clear how this addresses the issue however, as the problem happens in existing documents as well... Anytime i press backspace at the start of a paragraph the edit is done fine (it removes the new paragraph and joins the line i am on to the prior line), but the cursor ends up one position to the right of where it should be on the joined line (i.e. to the right of the character that it was to the left of when the backspace was pressed)

Line 1
Line 2

if i position at the start of Line 2 and press backspace i get

Line 1Line 2 (with cursor between the second 'L' and second 'i' where it should be between the '1' and the second 'L'

@jwbrown
Copy link
Author

jwbrown commented Oct 19, 2024

Hi again, we are looking to move towards an open beta and this is one of the few remaining issues... I'd happily chase inappwebview or summernote if this issue is likely to be theirs. I'm just unsure where to go next.... I have tied inserting java script to address the positioning but it does not seem to work to fix the problem

in onInit callback i added:

await webView.evaluateJavascript(source: """
              document.addEventListener('keydown', function(event) {
                if (event.key === 'Backspace') {
                  setTimeout(() => {
                    let selection = window.getSelection();
                    let range = selection.getRangeAt(0);

                    // Get the parent element where the cursor is currently located
                    let parentElement = range.startContainer.parentElement;

                    // Check if the cursor is in the middle of a merged paragraph
                    if (parentElement.tagName === 'P') {
                      let previousSibling = parentElement.previousSibling;
                      
                      // If the previous paragraph was merged, adjust cursor
                      if (previousSibling && previousSibling.tagName === 'P') {
                        // Get the merged text content
                        let combinedText = previousSibling.textContent + parentElement.textContent;

                        // Set the cursor to the correct position (after "more" and before "Ggg")
                        let cursorPosition = previousSibling.textContent.length;
                        previousSibling.textContent = combinedText; // Merge the texts
                        parentElement.remove(); // Remove the empty <p>

                        // Now set the cursor at the correct position in the merged paragraph
                        let newRange = document.createRange();
                        newRange.setStart(previousSibling.firstChild, cursorPosition);
                        newRange.setEnd(previousSibling.firstChild, cursorPosition);
                        selection.removeAllRanges();
                        selection.addRange(newRange);
                      }
                    }
                  }, 0);  // Ensure this runs after the content update
                }
              });
            """);

But still no change

@jwbrown
Copy link
Author

jwbrown commented Nov 2, 2024

Hi, sorry to chase up, but while the bug seems minor (just the position of the cursor after the backspace if the backspace joins 2 line) I am at standstill with no work around and would hate to try and find a new editor after all my work getting this one embedded and working other than this issue...

Any direction for resolving would be greatly appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants