Skip to content

Commit

Permalink
StringOutOfBoundException fix - from Twistle (#50)
Browse files Browse the repository at this point in the history
### Summary
Thanks to the fix from Twistle at
twistle@63f9c08

This should fix a StringOutOfBoundException when backspacing in the ChipTextView


#50
  • Loading branch information
simon-tse-hs authored Oct 18, 2018
1 parent 2f59629 commit 0084538
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions nachos/src/main/java/com/hootsuite/nachos/NachoTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,14 @@ public void onItemClick(AdapterView<?> adapterView, View view, int position, lon
int end = getSelectionEnd();
Editable editable = getText();
int start = mChipTokenizer.findTokenStart(editable, end);

// guard against java.lang.StringIndexOutOfBoundsException
start = Math.min(Math.max(0, start), editable.length());
end = Math.min(Math.max(0, end), editable.length());
if (end < start) {
end = start;
}

editable.replace(start, end, mChipTokenizer.terminateToken(text, data));

endUnwatchedTextChange();
Expand Down

0 comments on commit 0084538

Please sign in to comment.