Fix sending wrong requests for autocompletion (#414)

The problem was that Tusky kept sending requests for autocompletion
while writing toots even when the user wasn't typing a username
anymore. As it happened very often we would exceed the API request
limit and user wouldn't be able to send the toot.

This happened because Tokenizer is not used as expected. In fact,
during testing, findTokenEnd() and terminateToken() were never called.
I've tried setting a Validator but it wasn't used either. I'm not
sure what is the reason.

I am afraid it still may work incorrectly for the full nicknames
(ones with the instance name, like @name@isntance) because
the search may happen for the instance name but it's not as
critical.
main
Ivan Kupalov 7 years ago committed by Konrad Pozniak
parent 10b695fafd
commit d1d5766ea1
  1. 1
      app/src/main/java/com/keylesspalace/tusky/util/MentionTokenizer.java

@ -25,6 +25,7 @@ public class MentionTokenizer implements MultiAutoCompleteTextView.Tokenizer {
public int findTokenStart(CharSequence text, int cursor) { public int findTokenStart(CharSequence text, int cursor) {
int i = cursor; int i = cursor;
while (i > 0 && text.charAt(i - 1) != '@') { while (i > 0 && text.charAt(i - 1) != '@') {
if (!Character.isLetterOrDigit(text.charAt(i - 1))) return cursor;
i--; i--;
} }
if (i < 1 || text.charAt(i - 1) != '@') { if (i < 1 || text.charAt(i - 1) != '@') {

Loading…
Cancel
Save