aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Gultsch <daniel@gultsch.de>2017-01-20 13:45:09 +0100
committerDaniel Gultsch <daniel@gultsch.de>2017-01-20 13:45:09 +0100
commitc324f0c8dff5a07d10baf2e82f3d08dc446effdf (patch)
tree10ea988ef7e5f453a1401a768058517732e0b32c
parent59f82cbd341d105fc7ed90bc7bf4f5e59789958f (diff)
modified highlight nick behaviour to better work with quotes
-rw-r--r--src/main/java/eu/siacs/conversations/ui/ConversationFragment.java21
1 files 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 709244dd..e6d99579 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 + " ");
}
}