Open banasiak opened 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.
Thanks for the quick response. I'll play with it a bit and submit a pull request if I get it working.
@banasiak Have you got paste (Single and multiple) email working? Please if you completed it then help me.
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?
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?
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.
PR created: https://github.com/splitwise/TokenAutoComplete/pull/197 :)
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.
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.
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.
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.
please cherry-pick 6317aee01c5ef0afa72387ab1a1dc315616d588a for now, that would be helpful because that behavior easily be added in a subclass
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!