diff --git a/app/src/main/java/helium314/keyboard/latin/utils/TextExpanderUtils.kt b/app/src/main/java/helium314/keyboard/latin/utils/TextExpanderUtils.kt index f4164b8bb..6e0189468 100644 --- a/app/src/main/java/helium314/keyboard/latin/utils/TextExpanderUtils.kt +++ b/app/src/main/java/helium314/keyboard/latin/utils/TextExpanderUtils.kt @@ -6,7 +6,6 @@ package helium314.keyboard.latin.utils import android.content.ClipboardManager import android.content.Context -import android.content.res.ColorStateList import org.json.JSONObject import java.text.SimpleDateFormat import java.util.Date @@ -32,8 +31,6 @@ object TextExpanderUtils { return context.prefs().getBoolean(PREF_BACKSPACE_REVERTS, false) } - - data class ShortcutEntry( val template: String, val prefix: String = "" @@ -245,8 +242,9 @@ object TextExpanderUtils { val regex = Regex(patternStr, RegexOption.IGNORE_CASE) val expectedSuffix = prefix + word if (textBeforeCursor.endsWith(expectedSuffix, ignoreCase = true)) { - if (regex.matches(expectedSuffix)) { - val replaced = regex.replace(expectedSuffix, entry.template) + val matchInput = if (expectedSuffix.startsWith(prefix)) expectedSuffix.substring(prefix.length) else expectedSuffix + if (regex.matches(matchInput)) { + val replaced = regex.replace(matchInput, entry.template) return ExpandedResult(expand(replaced, context), prefix.length, expectedSuffix) } } @@ -276,3 +274,4 @@ object TextExpanderUtils { return null } } +