splitwise / TokenAutoComplete

Gmail style MultiAutoCompleteTextView for Android
Apache License 2.0
1.3k stars 384 forks source link

Is it possible to paste into TokenCompleteTextView? #95

Open banasiak opened 9 years ago

banasiak commented 9 years ago

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!

mgod commented 9 years ago

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 commented 9 years ago

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

SagarPanwala commented 9 years ago

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

saket commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

PR created: https://github.com/splitwise/TokenAutoComplete/pull/197 :)

mgod commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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