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

Wrong cursor placement when choosing from typeahead #4939

Open
alya opened this issue Aug 3, 2021 · 4 comments
Open

Wrong cursor placement when choosing from typeahead #4939

alya opened this issue Aug 3, 2021 · 4 comments
Labels
a-compose/send Compose box, autocomplete, camera/upload, outbox, sending bug help wanted

Comments

@alya
Copy link
Collaborator

alya commented Aug 3, 2021

When the user inserts a typeahead suggestion that already has some message text after it, the cursor doesn't get placed after the suggestion. Instead, it is placed somewhere in the middle of the typeahead suggestion that was selected. This happens for both @ mentions and stream names (#foo).

CZO thread

@alya alya added bug help wanted a-compose/send Compose box, autocomplete, camera/upload, outbox, sending labels Aug 3, 2021
@gnprice
Copy link
Member

gnprice commented Oct 23, 2021

Copying some information from that chat thread:

I took a quick look back at the implementation []: we just set the new value for the whole content of the input, and don't do anything to try to control where the cursor is.

So that behavior makes sense -- probably what the underlying input code is doing is something like, if your cursor was 80% of the way into the old text, then it gets placed 80% of the way into the [new] text. That's probably about the best that we could hope for the underlying input code to do, given the information we're giving it.

To fix this, we'll want to explicitly set where the cursor should be after the autocomplete. I expect there should be an API for that, and we totally have enough information to know what the right position should be, so I think this should be quite doable.

@SilentCruzer
Copy link
Contributor

I would like to work on this issue.

@WesleyAC
Copy link
Contributor

WesleyAC commented Jan 6, 2022

I looked into this a little bit today. This actually is a problem for emojis as well. For instance:

foo :heart| bar

autocompletes to:

foo :heart_eyes_c|at: bar

I think the fix here is to have getAutocompletedText return both a string and a selection — that's the place that has the info needed to make a decision about where the cursor should go.

@SilentCruzer
Copy link
Contributor

Right now in the app, we are getting the current position of the text cursor through the selection variable, but it has no connection with the Input and Autocomplete view component. So one possible solution is to add a selection prop to the Input component.

The problem with the solution is that the text cursor sometimes get stuck in a loop after autocomplete happens because of the selection props (see video below).

Changes made: link

textCursor.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-compose/send Compose box, autocomplete, camera/upload, outbox, sending bug help wanted
Projects
None yet
Development

No branches or pull requests

4 participants