From d171c6b3c6b021211ef5006c4f15af82a8569885 Mon Sep 17 00:00:00 2001 From: Helium314 Date: Fri, 31 May 2024 09:42:49 +0200 Subject: [PATCH] reduce issues when splitting layout with customized functional keys and uncommon space bar --- .../keyboard/keyboard/internal/KeyboardBuilder.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt index 73f6c01b4..f528f0117 100644 --- a/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt +++ b/app/src/main/java/helium314/keyboard/keyboard/internal/KeyboardBuilder.kt @@ -175,8 +175,13 @@ open class KeyboardBuilder(protected val mContext: Context, // insert spacer before first key that starts right of the center (also consider gap) var insertIndex = row.indexOfFirst { it.xPos + it.mAbsoluteWidth / 3 > mParams.mOccupiedWidth / 2 } .takeIf { it > -1 } ?: (row.size / 2) // fallback should never be needed, but better than having an error - if (row.any { it.mCode == Constants.CODE_SPACE }) { - val spaceLeft = row.single { it.mCode == Constants.CODE_SPACE } + val indexOfProperSpace = row.indexOfFirst { + // should work reasonably with customizable layouts, where space key might be completely different: + // "normal" width space keys are ignored, and the possibility of space being first in row is considered + it.mCode == Constants.CODE_SPACE && it.mWidth > row.first { !it.isSpacer && it.mCode != Constants.CODE_SPACE }.mWidth * 1.5f + } + if (indexOfProperSpace >= 0) { + val spaceLeft = row[indexOfProperSpace] reduceSymbolAndActionKeyWidth(row) insertIndex = row.indexOf(spaceLeft) + 1 val widthBeforeSpace = row.subList(0, insertIndex - 1).sumOf { it.mWidth }