From 02fd5e40d89e9e6d5494d8edefc4f10c84227ce9 Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Wed, 24 Jul 2024 22:20:10 +0300 Subject: [PATCH] Fix incorrect hint label when redundant keys are removed --- .../org/futo/inputmethod/keyboard/Key.java | 25 +++++++++++++++++-- .../keyboard/internal/MoreKeySpec.java | 5 ++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/java/src/org/futo/inputmethod/keyboard/Key.java b/java/src/org/futo/inputmethod/keyboard/Key.java index bb84e5d81..1888bcdca 100644 --- a/java/src/org/futo/inputmethod/keyboard/Key.java +++ b/java/src/org/futo/inputmethod/keyboard/Key.java @@ -440,8 +440,6 @@ public class Key implements Comparable { // Final attributes. mCode = key.mCode; mLabel = key.mLabel; - mHintLabel = key.mHintLabel; - mHintIconId = key.mHintIconId; mLabelFlags = key.mLabelFlags; mIconId = key.mIconId; mWidth = key.mWidth; @@ -461,6 +459,29 @@ public class Key implements Comparable { // Key state. mPressed = key.mPressed; mEnabled = key.mEnabled; + + + if (((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) || moreKeys == null || moreKeys.length == 0 || moreKeys[0].mLabel == null) { + mHintLabel = key.mHintLabel; + mHintIconId = key.mHintIconId; + } else { + String hintLabel = null; + String hintIcon = null; + + String hintLabelCandidate = moreKeys[0].mLabel; + if(hintLabelCandidate.startsWith("\\")) hintLabelCandidate = hintLabelCandidate.substring(1); + + if(hintLabelCandidate.length() == 1) { + hintLabel = moreKeys[0].mNeedsToUpperCase + ? StringUtils.toTitleCaseOfKeyLabel(hintLabelCandidate, moreKeys[0].mLocale) + : hintLabelCandidate; + } else if(hintLabelCandidate.contains("!icon/")) { + hintIcon = KeySpecParser.getIconId(hintLabelCandidate); + } + + mHintLabel = hintLabel; + mHintIconId = hintIcon; + } } @Nonnull diff --git a/java/src/org/futo/inputmethod/keyboard/internal/MoreKeySpec.java b/java/src/org/futo/inputmethod/keyboard/internal/MoreKeySpec.java index 7e2bfe676..47e7a98fb 100644 --- a/java/src/org/futo/inputmethod/keyboard/internal/MoreKeySpec.java +++ b/java/src/org/futo/inputmethod/keyboard/internal/MoreKeySpec.java @@ -52,11 +52,16 @@ public final class MoreKeySpec { public final String mOutputText; public final String mIconId; + public final boolean mNeedsToUpperCase; + public final Locale mLocale; + public MoreKeySpec(@Nonnull final String moreKeySpec, boolean needsToUpperCase, @Nonnull final Locale locale) { if (moreKeySpec.isEmpty()) { throw new KeySpecParser.KeySpecParserError("Empty more key spec"); } + mLocale = locale; + mNeedsToUpperCase = needsToUpperCase; final String label = KeySpecParser.getLabel(moreKeySpec); mLabel = needsToUpperCase ? StringUtils.toTitleCaseOfKeyLabel(label, locale) : label; final int codeInSpec = KeySpecParser.getCode(moreKeySpec);