Fix incorrect hint label when redundant keys are removed

This commit is contained in:
Aleksandras Kostarevas 2024-07-24 22:20:10 +03:00
parent 7e0234cb22
commit 02fd5e40d8
2 changed files with 28 additions and 2 deletions

View File

@ -440,8 +440,6 @@ public class Key implements Comparable<Key> {
// 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> {
// 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

View File

@ -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);