@@ -391,8 +391,9 @@ protected String currentCompletionText() {
391391 if (hintVisible ) return "" ; //Can't have any text if the hint is visible
392392
393393 Editable editable = getText ();
394- int end = getSelectionEnd ();
395- int start = tokenizer .findTokenStart (editable , end );
394+ int cursorPosition = getSelectionEnd ();
395+ int end = tokenizer .findTokenEnd (editable , cursorPosition );
396+ int start = tokenizer .findTokenStart (editable , cursorPosition );
396397 if (start < prefix .length ()) {
397398 start = prefix .length ();
398399 }
@@ -428,12 +429,19 @@ public void invalidate() {
428429 public boolean enoughToFilter () {
429430 Editable text = getText ();
430431
431- int end = getSelectionEnd ();
432- if ( end < 0 || tokenizer == null ) {
432+ if ( tokenizer == null )
433+ {
433434 return false ;
434435 }
435436
436- int start = tokenizer .findTokenStart (text , end );
437+ int cursorPosition = getSelectionEnd ();
438+
439+ if (cursorPosition < 0 ) {
440+ return false ;
441+ }
442+
443+ int end = tokenizer .findTokenEnd (text , cursorPosition );
444+ int start = tokenizer .findTokenStart (text , cursorPosition );
437445 if (start < prefix .length ()) {
438446 start = prefix .length ();
439447 }
@@ -774,8 +782,9 @@ protected void replaceText(CharSequence text) {
774782 TokenImageSpan tokenSpan = buildSpanForObject (selectedObject );
775783
776784 Editable editable = getText ();
777- int end = getSelectionEnd ();
778- int start = tokenizer .findTokenStart (editable , end );
785+ int cursorPosition = getSelectionEnd ();
786+ int end = tokenizer .findTokenEnd (editable , cursorPosition );
787+ int start = tokenizer .findTokenStart (editable , cursorPosition );
779788 if (start < prefix .length ()) {
780789 start = prefix .length ();
781790 }
0 commit comments