diff options
Diffstat (limited to 'srcs/juloo.keyboard2/ComposeKey.java')
| -rw-r--r-- | srcs/juloo.keyboard2/ComposeKey.java | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/srcs/juloo.keyboard2/ComposeKey.java b/srcs/juloo.keyboard2/ComposeKey.java index f2169b1..57b2a4e 100644 --- a/srcs/juloo.keyboard2/ComposeKey.java +++ b/srcs/juloo.keyboard2/ComposeKey.java @@ -4,31 +4,22 @@ import java.util.Arrays; public final class ComposeKey { - /** Apply the pending compose sequence to [kv]. */ + /** Apply the pending compose sequence to [kv]. Returns [null] if no sequence + matched. */ public static KeyValue apply(int state, KeyValue kv) { switch (kv.getKind()) { case Char: - KeyValue res = apply(state, kv.getChar()); - // Grey-out characters not part of any sequence. - if (res == null) - return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED); - return res; - /* Tapping compose again exits the pending sequence. */ - case Compose_pending: - return KeyValue.getKeyByName("compose_cancel"); - /* These keys are not greyed. */ - case Event: - case Modifier: - return kv; - /* Other keys cannot be part of sequences. */ - default: - return kv.withFlags(kv.getFlags() | KeyValue.FLAG_GREYED); + return apply(state, kv.getChar()); + case String: + return apply(state, kv.getString()); } + return null; } - /** Apply the pending compose sequence to char [c]. */ + /** Apply the pending compose sequence to char [c]. Returns [null] if no + sequence matched. */ public static KeyValue apply(int prev, char c) { char[] states = ComposeKeyData.states; @@ -51,6 +42,23 @@ public final class ComposeKey return KeyValue.makeCharKey((char)next_header); } + /** Apply each char of a string to a sequence. Returns [null] if no sequence + matched. */ + public static KeyValue apply(int prev, String s) + { + int i = 0; + while (true) + { + KeyValue k = apply(prev, s.charAt(i)); + i++; + if (k == null) return null; + if (i >= s.length()) return k; + if (k.getKind() != KeyValue.Kind.Compose_pending) + return null; // Found a final state before the end of [s]. + prev = k.getPendingCompose(); + } + } + /** The state machine is comprised of two arrays. The [states] array represents the different states and the associated |
