Skip to content

Commit 76a74c2

Browse files
committed
fix: SnyggSelector crash on unknown selectors and copy-paste serializationId
SnyggSelector.from() used entries.first() which throws NoSuchElementException on unrecognized selector strings from imported theme files. Changed to firstOrNull() with NONE fallback so malformed themes degrade gracefully instead of crashing the IME. SnyggContentScaleValue.serializationId was "textAlign" (copy-pasted from SnyggTextAlignValue). Corrected to "contentScale".
1 parent 86c9885 commit 76a74c2

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

lib/snygg/src/main/kotlin/org/florisboard/lib/snygg/SnyggRule.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ enum class SnyggSelector(val id: String) {
542542
internal fun from(str: String): SnyggSelector {
543543
if (str.isNotEmpty()) {
544544
val selector = str.substring(1)
545-
return entries.first { it.id == selector }
545+
return entries.firstOrNull { it.id == selector } ?: NONE
546546
}
547547
return NONE
548548
}

lib/snygg/src/main/kotlin/org/florisboard/lib/snygg/value/SnyggUriValue.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ data class SnyggUriValue(val uri: String) : SnyggValue {
5454

5555
data class SnyggContentScaleValue(val contentScale: ContentScale) : SnyggValue {
5656
companion object : SnyggEnumLikeValueEncoder<ContentScale>(
57-
serializationId = "textAlign",
57+
serializationId = "contentScale",
5858
serializationMapping = mapOf(
5959
"crop" to ContentScale.Crop,
6060
"fill-bounds" to ContentScale.FillBounds,

0 commit comments

Comments
 (0)