From 88dcacc823d99d523d2b08d474986f97661c526d Mon Sep 17 00:00:00 2001 From: M66B Date: Tue, 22 Feb 2022 19:50:11 +0100 Subject: [PATCH] Delete chip on backspace --- .../faircode/email/EditTextMultiAutoComplete.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/EditTextMultiAutoComplete.java b/app/src/main/java/eu/faircode/email/EditTextMultiAutoComplete.java index 68039e7b50..2fa39aa600 100644 --- a/app/src/main/java/eu/faircode/email/EditTextMultiAutoComplete.java +++ b/app/src/main/java/eu/faircode/email/EditTextMultiAutoComplete.java @@ -190,9 +190,11 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie }; addTextChangedListener(new TextWatcher() { + Integer backspace = null; + @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { - // Do nothing + backspace = (count - after == 1 ? start : null); } @Override @@ -202,6 +204,15 @@ public class EditTextMultiAutoComplete extends AppCompatMultiAutoCompleteTextVie @Override public void afterTextChanged(Editable edit) { + if (backspace != null) { + ClipImageSpan[] spans = edit.getSpans(backspace, backspace, ClipImageSpan.class); + if (spans.length == 1) { + int start = edit.getSpanStart(spans[0]); + int end = edit.getSpanEnd(spans[0]); + edit.delete(start, end); + } + } + if (getWidth() == 0) post(update); else