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

Is it possible to paste into TokenCompleteTextView? #95

Open
banasiak opened this issue Jan 16, 2015 · 12 comments
Open

Is it possible to paste into TokenCompleteTextView? #95

banasiak opened this issue Jan 16, 2015 · 12 comments

Comments

@banasiak
Copy link

I see that the TokenCompleteTextView is calling setLongClickable(false). Changing that to true causes all kinds of havoc when selecting a token. Do you have any ideas how I could paste into this text view without those side effects? Thanks in advance!

@banasiak banasiak changed the title Is it possible to paste into ChipTextView? Is it possible to paste into TokenCompleteTextView? Jan 16, 2015
@mgod
Copy link
Contributor

mgod commented Jan 16, 2015

At the moment, pasting into the field will cause a disaster. I haven't handled any of the overrides to make paste work. I think the only thing that would need handling would be onTextContextMenuItem but I don't really have enough experience to tell how hard this would be.

@banasiak
Copy link
Author

Thanks for the quick response. I'll play with it a bit and submit a pull request if I get it working.

@SagarPanwala
Copy link

@banasiak Have you got paste (Single and multiple) email working?
Please if you completed it then help me.

@saket
Copy link

saket commented Jan 16, 2016

onTextContextMenuItem is for handling the menu action. But the context menu doesn't appear in TokenCompleteTextView at all. Any idea how can I enable this?

@saket
Copy link

saket commented Jan 16, 2016

Update: Okay, so simply enabling long-press on TokenCompleteTextView by calling setLongClickable(true) was enough. The text in clipboard gets pasted into the field, triggering the suggestions.

This brings me to the question — why did you disable long-press in the first step?

@saket
Copy link

saket commented Jan 17, 2016

Update 2: Enabling cut / copy leads is breaking TokenCompleteTextView's ability to ignore duplicate tokens.

When a cut or copy action is received, it seems that Android re-inserts the spannable text within selection to the field, essentially making TokenCompleteTextView think that a new token was added. This results in the objects field now having duplicate items.

So even if you remove the token, one copy of that token will still be present in objects. And you cannot add that token again since duplicates aren't allowed.

A probable solution is to add another check for duplicates inside TokenSpanWatcher.onSpanAdded() before actually saving the inserted token.

I'll raise a PR with my changes.

@saket
Copy link

saket commented Jan 17, 2016

PR created: #197 :)

@mgod
Copy link
Contributor

mgod commented Feb 1, 2016

The two reasons I disabled paste were that it was unreliable on some versions of Android (sadly I didn't keep notes on this) and that I could not figure out a good UX for what happens if you paste in multiple tokens. As you noted, getting this working is as simple as re-enabling long press. I'm happy to re-verify paste on all the supported Android versions, but I don't want to add this back into the main repo until we have a good consistent experience for pasting multiple tokens.

@saket
Copy link

saket commented Feb 1, 2016

You can let the subclass handle the pasted text when multiple tokens are pasted. I've added this to my fork of your library and it works pretty well.

@mgod
Copy link
Contributor

mgod commented Feb 1, 2016

Sure, but that doesn't mean paste should be on by default. I'm happy to merge the prevent duplicates changes from you PR, but enabling long press should not be the default behavior. It should be possible to override this in your subclass.

@saket
Copy link

saket commented Feb 2, 2016

Sounds good. I can improve that PR by letting the subclass handle what to do with the pasted tokens. The currently open PR handles this in a dumb way by simply pasting the entire content into the field.

@Valodim
Copy link
Contributor

Valodim commented Jul 21, 2016

please cherry-pick 6317aee for now, that would be helpful because that behavior easily be added in a subclass

Valodim added a commit to thunderbird/thunderbird-android that referenced this issue Jul 22, 2016
this leads to some problems if more than one token is actually parsed.
however, for the common use case of parsing a single address, it seems
to work just fine, so this hopefully does more good than harm.

see also splitwise/TokenAutoComplete#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants