From 07fe859e357376132650ec065f7cf577219dcace Mon Sep 17 00:00:00 2001 From: Grishka Date: Wed, 20 Apr 2022 18:37:04 +0300 Subject: [PATCH] Fix compose autocomplete for emojis --- mastodon/build.gradle | 2 +- .../android/fragments/ComposeFragment.java | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mastodon/build.gradle b/mastodon/build.gradle index 3ceaf30f..5679e75a 100644 --- a/mastodon/build.gradle +++ b/mastodon/build.gradle @@ -9,7 +9,7 @@ android { applicationId "org.joinmastodon.android" minSdk 23 targetSdk 31 - versionCode 28 + versionCode 29 versionName "1.0.1" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java index bd2df736..5b727ee0 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ComposeFragment.java @@ -76,9 +76,9 @@ import org.joinmastodon.android.ui.text.ComposeHashtagOrMentionSpan; import org.joinmastodon.android.ui.text.HtmlParser; import org.joinmastodon.android.ui.utils.SimpleTextWatcher; import org.joinmastodon.android.ui.utils.UiUtils; +import org.joinmastodon.android.ui.views.ComposeEditText; import org.joinmastodon.android.ui.views.ComposeMediaLayout; import org.joinmastodon.android.ui.views.ReorderableLinearLayout; -import org.joinmastodon.android.ui.views.ComposeEditText; import org.joinmastodon.android.ui.views.SizeListenerLinearLayout; import org.parceler.Parcel; import org.parceler.Parcels; @@ -91,12 +91,10 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import androidx.annotation.DrawableRes; import me.grishka.appkit.Nav; import me.grishka.appkit.api.Callback; import me.grishka.appkit.api.ErrorResponse; import me.grishka.appkit.fragments.OnBackPressedListener; -import me.grishka.appkit.fragments.ToolbarFragment; import me.grishka.appkit.imageloader.ViewImageLoader; import me.grishka.appkit.imageloader.requests.UrlImageLoaderRequest; import me.grishka.appkit.utils.V; @@ -416,14 +414,17 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr } char firstChar=editable.charAt(spanStart); String spanText=s.subSequence(spanStart, spanEnd).toString(); - if(firstChar=='@' || firstChar=='#'){ - Matcher matcher=HIGHLIGHT_PATTERN.matcher(spanText); - if(!matcher.find()){ // invalid mention, remove + if(firstChar=='@' || firstChar=='#' || firstChar==':'){ + Matcher matcher=AUTO_COMPLETE_PATTERN.matcher(spanText); + char prevChar=spanStart>0 ? editable.charAt(spanStart-1) : ' '; + if(!matcher.find() || !Character.isWhitespace(prevChar)){ // invalid mention, remove editable.removeSpan(span); continue; }else if(matcher.end()+spanStart