diff --git a/app/src/main/java/app/fedilab/android/activities/TootActivity.java b/app/src/main/java/app/fedilab/android/activities/TootActivity.java index 090e6646d..6bf7843a9 100644 --- a/app/src/main/java/app/fedilab/android/activities/TootActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/TootActivity.java @@ -228,7 +228,6 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, private Toast mToast; private RelativeLayout drawer_layout; private HorizontalScrollView picture_scrollview; - private int searchLength; private TextView toot_space_left; private String initialContent; public static final int MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE = 754; @@ -2381,6 +2380,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, public void onItemClick(AdapterView parent, View view, int position, long id) { Account account = accounts.get(position); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length()) deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition); else { @@ -2455,6 +2458,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, public void onItemClick(AdapterView parent, View view, int position, long id) { String shortcode = emojis.get(position).getShortcode(); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() ) deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition); else { @@ -2605,6 +2612,10 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate, return; String tag = tags.get(position); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() ) deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition); else { diff --git a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java index 5025cf411..a53197887 100644 --- a/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java +++ b/app/src/main/java/app/fedilab/android/drawers/StatusListAdapter.java @@ -303,7 +303,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onRetrieveSearchAccounts(APIResponse apiResponse) { if( apiResponse.getError() != null) return; - int searchLength = 15; + final List accounts = apiResponse.getAccounts(); if( accounts != null && accounts.size() > 0){ int currentCursorPosition = toot_content.getSelectionStart(); @@ -320,6 +320,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onItemClick(AdapterView parent, View view, int position, long id) { Account account = accounts.get(position); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if (currentCursorPosition - searchLength > 0 && currentCursorPosition < oldContent.length()) deltaSearch = oldContent.substring(currentCursorPosition - searchLength, currentCursorPosition); else { @@ -356,7 +360,7 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct @Override public void onRetrieveSearchEmoji(List emojis) { int currentCursorPosition = toot_content.getSelectionStart(); - int searchLength = 15; + if( emojis != null && emojis.size() > 0){ EmojisSearchAdapter emojisSearchAdapter = new EmojisSearchAdapter(context, emojis); toot_content.setThreshold(1); @@ -369,6 +373,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct public void onItemClick(AdapterView parent, View view, int position, long id) { String shortcode = emojis.get(position).getShortcode(); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() ) deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition); else { @@ -400,7 +408,6 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct if( apiResponse == null || apiResponse.getResults() == null) return; - int searchLength = 15; app.fedilab.android.client.Entities.Results results = apiResponse.getResults(); int currentCursorPosition = toot_content.getSelectionStart(); final List tags = results.getHashtags(); @@ -423,6 +430,10 @@ public class StatusListAdapter extends RecyclerView.Adapter implements OnPostAct return; String tag = tags.get(position); String deltaSearch = ""; + int searchLength = 15; + if (currentCursorPosition < 15) { //Less than 15 characters are written before the cursor position + searchLength = currentCursorPosition; + } if( currentCursorPosition-searchLength > 0 && currentCursorPosition < oldContent.length() ) deltaSearch = oldContent.substring(currentCursorPosition-searchLength, currentCursorPosition); else {