Skip to content

Commit 88b3a09

Browse files
committed
Show hints in symbols menu by default
1 parent 0a5ce6b commit 88b3a09

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

java/src/org/futo/inputmethod/v2keyboard/LayoutEngine.kt

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import androidx.compose.ui.unit.Dp
66
import org.futo.inputmethod.keyboard.KeyConsts
77
import org.futo.inputmethod.keyboard.internal.KeyboardLayoutElement
88
import org.futo.inputmethod.keyboard.internal.KeyboardParams
9+
import org.futo.inputmethod.keyboard.internal.isAlphabet
910
import org.futo.inputmethod.latin.R
1011
import org.futo.inputmethod.latin.common.Constants
1112
import org.futo.inputmethod.latin.uix.DynamicThemeProvider
@@ -499,7 +500,20 @@ data class LayoutEngine(
499500
}
500501
}
501502

502-
private val validNumbersForHint = "1234567890".map { params.mTextsSet.resolveTextReference("!text/keyspec_symbols_$it") ?: it }.toSet()
503+
private val validNumbersForHint = "1234567890".map { it.toString() }.map { params.mTextsSet.resolveTextReference("!text/keyspec_symbols_$it") ?: it }.toSet()
504+
private val englishNumbers = "1234567890".map { it.toString() }.toSet()
505+
private val blacklistedHintsForNumbers = buildList {
506+
// Subscripts/superscripts, fractions
507+
addAll((0x2070 .. 0x208E).map { it.toChar() })
508+
addAll((0x2150 .. 0x215F).map { it.toChar() })
509+
add('\u00B0')
510+
add('\u00B2')
511+
add('\u00B3')
512+
add('\u00B9')
513+
add('\u00BC')
514+
add('\u00BD')
515+
add('\u00BE')
516+
}.map { it.toString() }.toSet()
503517
private val showAllHintsSetting = params.mId.mLongPressKeySettings.showHints
504518

505519
private fun computedKeyToKey(data: ComputedKeyData, x: Int, y: Int, width: Int, height: Int, leftGap: LayoutEntry.Gap?, rightGap: LayoutEntry.Gap?): org.futo.inputmethod.keyboard.Key? {
@@ -529,11 +543,21 @@ data class LayoutEngine(
529543
hasExplicitHint -> data.hint
530544

531545
// If we have no explicit hint, and show hints setting is disabled,
532-
// then either show a number or nothing
533-
!showAllHintsSetting ->
534-
data.moreKeys.mapNotNull { it.mLabel }.firstOrNull { validNumbersForHint.contains(it) } ?: ""
535-
536-
// If we have no explicit hint and show hints setting is enabled,
546+
// then in alphabet menu, either show a number or nothing
547+
!showAllHintsSetting && params.mId.mElement.kind.isAlphabet ->
548+
data.moreKeys.mapNotNull { it.mLabel }.firstOrNull { validNumbersForHint.contains(it) && it != data.label } ?: ""
549+
550+
// In the situation that this is a number, only show a hint if it's not a tiny little
551+
// superscript or subscript
552+
englishNumbers.contains(data.label) && validNumbersForHint.contains(data.label)
553+
->
554+
data.moreKeys.firstOrNull {
555+
it.mLabel != null
556+
&& !blacklistedHintsForNumbers.contains(it.mLabel)
557+
&& it.mLabel != data.label
558+
}?.mLabel ?: ""
559+
560+
// If we have no explicit hint and show hints setting is enabled (or we are in symbols menu),
537561
// set this to null which will later automatically select a hint based on
538562
// the first element of moreKeys
539563
else -> null

0 commit comments

Comments
 (0)