abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2/ComposeKey.java
diff options
context:
space:
mode:
authorJules Aguillon2026-04-10 19:08:23 +0200
committerGitHub2026-04-10 19:08:23 +0200
commit833b4a21549f7ea8067291f344f6acdeaff3f079 (patch)
tree81448d90ea6260e49a0b7e02595f8c4f5508eda0 /srcs/juloo.keyboard2/ComposeKey.java
parent8921de7f02570ba03816ebb4025f2c95bc131707 (diff)
downloadunexpected-keyboard-833b4a21549f7ea8067291f344f6acdeaff3f079.tar.gz
unexpected-keyboard-833b4a21549f7ea8067291f344f6acdeaff3f079.zip
Better suggestion with diacritics (#1223)
* Update cdict * scripts/subst_of_compose.py: Compute substitutions from compose mappings. They are used when building dictionaries. * Add substitutions compose data * Better suggestion with diacritics This improves the suggestions for words that contain diacritics and uppercase letters. This works by stripping diacritics both when building the dictionaries (using word aliases added in cdict: https://github.com/Julow/cdict/pull/3) and during lookup. Cdict then takes care of resolving the correct word. The substitutions are generated using mappings from `fn`, `shift` and all the `accent_*` modifiers into srcs/compose/substitutions.json This can be updated easily when more mappings are added.
Diffstat (limited to 'srcs/juloo.keyboard2/ComposeKey.java')
-rw-r--r--srcs/juloo.keyboard2/ComposeKey.java27
1 files changed, 23 insertions, 4 deletions
diff --git a/srcs/juloo.keyboard2/ComposeKey.java b/srcs/juloo.keyboard2/ComposeKey.java
index 5be9597..3d97d69 100644
--- a/srcs/juloo.keyboard2/ComposeKey.java
+++ b/srcs/juloo.keyboard2/ComposeKey.java
@@ -22,14 +22,14 @@ public final class ComposeKey
return null;
}
- /** Apply the pending compose sequence to char [c]. Returns [null] if no
+ /** Apply a char to the pending compose sequence. Returns [null] if no
sequence matched. */
- public static KeyValue apply(int prev, char c)
+ public static KeyValue apply(int state, char c)
{
char[] states = ComposeKeyData.states;
char[] edges = ComposeKeyData.edges;
- int prev_length = edges[prev];
- int next = Arrays.binarySearch(states, prev + 1, prev + prev_length, c);
+ int state_length = edges[state];
+ int next = Arrays.binarySearch(states, state + 1, state + state_length, c);
if (next < 0)
return null;
next = edges[next];
@@ -46,6 +46,25 @@ public final class ComposeKey
return KeyValue.makeCharKey((char)next_header);
}
+ /** Apply char [c] to the pending compose sequence. If the application resolves
+ to a final char state, return it, otherwise return [0]. This is faster
+ than [apply] but do not support sequences of more than 1 char. Used to
+ apply substitutions for word suggestions. */
+ public static char transform_char(int state, char c)
+ {
+ char[] states = ComposeKeyData.states;
+ char[] edges = ComposeKeyData.edges;
+ int state_length = edges[state];
+ int next = Arrays.binarySearch(states, state + 1, state + state_length, c);
+ if (next < 0)
+ return 0;
+ next = edges[next];
+ int next_header = states[next];
+ if (next_header == 0 || next_header == 0xFFFF)
+ return 0;
+ return (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)