From c324f0c8dff5a07d10baf2e82f3d08dc446effdf Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Fri, 20 Jan 2017 13:45:09 +0100 Subject: [PATCH] modified highlight nick behaviour to better work with quotes --- .../ui/ConversationFragment.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 709244dda..e6d995798 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -34,6 +34,7 @@ import android.widget.AbsListView; import android.widget.AbsListView.OnScrollListener; import android.widget.AdapterView; import android.widget.AdapterView.AdapterContextMenuInfo; +import android.widget.EditText; import android.widget.ImageButton; import android.widget.ListView; import android.widget.RelativeLayout; @@ -849,16 +850,22 @@ public class ConversationFragment extends Fragment implements EditMessage.Keyboa } protected void highlightInConference(String nick) { - String oldString = mEditMessage.getText().toString().trim(); - if (oldString.isEmpty() || mEditMessage.getSelectionStart() == 0) { + final Editable editable = mEditMessage.getText(); + String oldString = editable.toString().trim(); + final int pos = mEditMessage.getSelectionStart(); + if (oldString.isEmpty() || pos == 0) { mEditMessage.getText().insert(0, nick + ": "); } else { - if (mEditMessage.getText().charAt( - mEditMessage.getSelectionStart() - 1) != ' ') { - nick = " " + nick; + final char before = editable.charAt(pos - 1); + final char after = editable.length() > pos ? editable.charAt(pos) : '\0'; + if (before == '\n') { + editable.insert(pos, nick + ": "); + } else { + editable.insert(pos,(Character.isWhitespace(before)? "" : " ") + nick + (Character.isWhitespace(after) ? "" : " ")); + if (Character.isWhitespace(after)) { + mEditMessage.setSelection(mEditMessage.getSelectionStart()+1); + } } - mEditMessage.getText().insert(mEditMessage.getSelectionStart(), - nick + " "); } }