From 465fc86e613ecc00359ee682c1c71c362674b1d8 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 12 Jan 2025 21:04:32 +0100 Subject: [PATCH] add new groupId -1 for suppressing default popups e.g. on action or comma keys fixes #1243 --- .../internal/keyboard_parser/floris/TextKeyData.kt | 11 ++++++++--- layouts.md | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt index 3c6fb28f..b26d3a08 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/keyboard_parser/floris/TextKeyData.kt @@ -56,11 +56,10 @@ sealed interface KeyData : AbstractKeyData { fun copy(newType: KeyType? = type, newCode: Int = code, newLabel: String = label, newGroupId: Int = groupId, newPopup: PopupSet = popup, newWidth: Float = width, newLabelFlags: Int = labelFlags): KeyData - // groups (currently) not supported companion object { /** * Constant for the default group. If not otherwise specified, any key is automatically - * assigned to this group. + * assigned to this group. Additional popup keys will be added for specific labels. */ const val GROUP_DEFAULT: Int = 0 @@ -82,6 +81,11 @@ sealed interface KeyData : AbstractKeyData { */ const val GROUP_ENTER: Int = 3 + /** + * Constant for the default key, but without assigning popups for special labels. + */ + const val GROUP_NO_DEFAULT_POPUP: Int = -1 + /** * Constant for the enter modifier key group. Any key belonging to this group will get the * popups specified for "~kana" in the popup mapping. @@ -335,7 +339,7 @@ sealed interface KeyData : AbstractKeyData { } override fun compute(params: KeyboardParams): KeyData? { - require(groupId in 0..GROUP_ENTER) { "only positive groupIds up to GROUP_ENTER are supported" } + require(groupId in GROUP_NO_DEFAULT_POPUP..GROUP_ENTER) { "only groupIds from -1 to 3 are supported" } require(label.isNotEmpty() || type == KeyType.PLACEHOLDER || code != KeyCode.UNSPECIFIED) { "non-placeholder key has no code and no label" } require(width >= 0f || width == -1f) { "illegal width $width" } val newLabel = label.convertFlorisLabel().resolveStringLabel(params) @@ -541,6 +545,7 @@ sealed interface KeyData : AbstractKeyData { if (groupId == GROUP_COMMA) return SimplePopups(getCommaPopupKeys(params)) if (groupId == GROUP_PERIOD) return SimplePopups(getPunctuationPopupKeys(params)) if (groupId == GROUP_ENTER) return getActionKeyPopupKeys(params) + if (groupId == GROUP_NO_DEFAULT_POPUP) return null return when (label) { KeyLabel.COMMA -> SimplePopups(getCommaPopupKeys(params)) KeyLabel.PERIOD -> SimplePopups(getPunctuationPopupKeys(params)) diff --git a/layouts.md b/layouts.md index f312f2d5..58755e49 100644 --- a/layouts.md +++ b/layouts.md @@ -58,7 +58,7 @@ If the layout has exactly 2 keys in the bottom row, these keys will replace comm * `codePoints`: when multiple code points should be entered, only available for `multi_text_key` * `label`: text to display on the key, determined from code if empty * There are some special values, see the [label section](#labels) -* `groupId`: which additional popup keys to show, `0` is default and does not add anything, `1` adds the comma popup keys, `2` adds the period popup keys, `3` adds the action key popup keys (looks awkward though) +* `groupId`: which additional popup keys to show, `0` is default and does not add anything, `1` adds the comma popup keys, `2` adds the period popup keys, `3` adds the action key popup keys (looks awkward though), `-1` suppresses additional popups based on the label * `popup`: list of keys to add in the popup, e.g. `"label": ")", "popup": {"relevant": [{ "label": "." }]}` is a `)` key with a `.` popup * Note that in popup keys, properties are ignored with the exception of `$`, `code`, `codePoints`, and `label` * When specifying a _selector_ key class in a popup key, it will be evaluated correctly (e.g. for changing popups dependent on shift state)