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

Cursor move to wrong position after inserting text longer than 1 character - with solution #216

Closed
sslater11 opened this issue May 8, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@sslater11
Copy link
Contributor

sslater11 commented May 8, 2023

When we insert text using a button that inserts a string with more than one character, the cursor ends up in the wrong place.
E.g. Thumb-Key English v4 (Programmer) can insert "https://", but the cursor moves to the wrong place after inserting.

To Reproduce

  1. Change to Thumb-Key English v4 (Programmer)
  2. type 'ooooooooooooooo'
  3. Click in the middle of that text to move the cursor there
  4. Swipe up on the 'A' key, then we see the 'T' key now has "https://"
  5. Swipe left on the T key to insert "https://"
  6. Notice the cursor is now several letters away from the text it input. It's distance is the length of inserted text - 1 place away.

Solution
Change line 186 in
thumb-key/app/src/main/java/com/dessalines/thumbkey/utils/Utils.kt

change this

            ime.currentInputConnection.commitText(
                text,
                text.length // this is wrong
            )

to this

            ime.currentInputConnection.commitText(
                text,
                1 // This works for single characters, or any length of text we enter, including empty strings.
            )

Is there any point making a pull request? it's only one line that needs changing.

Setting a value to 0 will make the cursor appear before the text inserted, 1 is after the text inserted. Any other number is x places away from the inserted text, and you can even use negative numbers to move the cursor left.
I also tested this solution with a key that has an empty string, and the cursor stays where it is, which is what you would expect to happen.

@sslater11 sslater11 added the bug Something isn't working label May 8, 2023
@dessalines
Copy link
Owner

Sure, if you tested it already, do a PR.

@sslater11
Copy link
Contributor Author

I've created a pull request that fixes this. I also made the animation look smoother, and made a Toast() notification for when the user switches layouts :).
Pull Request #218

@dessalines
Copy link
Owner

Thanks for these!

mpice-mn pushed a commit to mpice-mn/thumb-key that referenced this issue Sep 23, 2023
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

2 participants