move zwj and zwnj codes from Constants to KeyCode

and support florisboard name half_space for zwnj
This commit is contained in:
Helium314 2024-03-27 06:10:31 +01:00
parent cd44d2dc9f
commit e289e7ef5f
5 changed files with 9 additions and 7 deletions

View file

@ -30,6 +30,7 @@ import androidx.annotation.Nullable;
import helium314.keyboard.keyboard.emoji.EmojiPageKeyboardView;
import helium314.keyboard.keyboard.internal.KeyDrawParams;
import helium314.keyboard.keyboard.internal.KeyVisualAttributes;
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode;
import helium314.keyboard.latin.R;
import helium314.keyboard.latin.common.ColorType;
import helium314.keyboard.latin.common.Colors;
@ -640,7 +641,7 @@ public class KeyboardView extends View {
} else if (this instanceof PopupKeysKeyboardView) {
// set color filter for long press comma key, should not trigger anywhere else
mColors.setColor(icon, ColorType.KEY_ICON);
} else if (key.getCode() == Constants.CODE_SPACE || key.getCode() == 0x200C) {
} else if (key.getCode() == Constants.CODE_SPACE || key.getCode() == KeyCode.ZWNJ) {
// set color of default number pad space bar icon for Holo style, or for zero-width non-joiner (zwnj) on some layouts like nepal
mColors.setColor(icon, ColorType.KEY_ICON);
}

View file

@ -116,7 +116,8 @@ object KeyCode {
const val KANA_HALF_KATA = -9713
const val KESHIDA = 1600
const val HALF_SPACE = 8204
const val ZWNJ = 8204 // 0x200C, named HALF_SPACE in FlorisBoard
const val ZWJ = 8205 // 0x200D
const val CJK_SPACE = 12288
@ -154,6 +155,7 @@ object KeyCode {
}
/** to make sure a FlorisBoard label works when reading a JSON layout */
// resulting special labels should be names of FunctionalKey enum, case insensitive
fun String.convertFlorisLabel(): String = when (this) {
"view_characters" -> "alpha"
"view_symbols" -> "symbol"
@ -170,6 +172,7 @@ object KeyCode {
"currency_slot_5" -> "$$$4"
"currency_slot_6" -> "$$$5"
"enter" -> "action"
"half_space" -> "zwnj"
else -> this
}
}

View file

@ -110,7 +110,7 @@ sealed interface KeyData : AbstractKeyData {
fun isSpaceKey(): Boolean {
return type == KeyType.CHARACTER && (code == Constants.CODE_SPACE || code == KeyCode.CJK_SPACE
|| code == KeyCode.HALF_SPACE || code == KeyCode.KESHIDA)
|| code == KeyCode.ZWNJ || code == KeyCode.KESHIDA)
}
fun toKeyParams(params: KeyboardParams, width: Float = params.mDefaultRelativeKeyWidth, additionalLabelFlags: Int = 0): Key.KeyParams {

View file

@ -191,8 +191,6 @@ public final class Constants {
public static final String REGEXP_PERIOD = "\\.";
public static final String STRING_SPACE = " ";
public static final int CODE_ZWNJ = '\u200C';
public static final int CODE_ZWJ = '\u200D';
public static boolean isLetterCode(final int code) {
return code >= CODE_SPACE;

View file

@ -2,6 +2,7 @@
package helium314.keyboard.latin.common
import helium314.keyboard.keyboard.internal.keyboard_parser.floris.KeyCode
import helium314.keyboard.latin.common.StringUtils.mightBeEmoji
import helium314.keyboard.latin.common.StringUtils.newSingleCodePointString
import helium314.keyboard.latin.settings.SpacingAndPunctuations
@ -62,8 +63,7 @@ fun getFullEmojiAtEnd(s: CharSequence): String {
// stop if codepoint can't be emoji
if (!mightBeEmoji(codepoint)) return ""
offset -= Character.charCount(codepoint)
if (offset > 0 && text[offset - 1].code == Constants.CODE_ZWJ) {
// continue if ZWJ
if (offset > 0 && text[offset - 1].code == KeyCode.ZWJ) {
offset -= 1
continue
}