abouttreesummaryrefslogcommitdiff
path: root/srcs
diff options
context:
space:
mode:
authorJules Aguillon2023-01-30 21:29:59 +0100
committerJules Aguillon2023-01-30 21:29:59 +0100
commit2539feadcd370e98d3750f6b6b06664e0eb14d0b (patch)
treede190a6645c6843484269d733437dfa49efcbbbd /srcs
parent5f283cd0cd3df4761b924ffae91c59862d4ecc89 (diff)
downloadunexpected-keyboard-2539feadcd370e98d3750f6b6b06664e0eb14d0b.tar.gz
unexpected-keyboard-2539feadcd370e98d3750f6b6b06664e0eb14d0b.zip
Fix placeholder key not replaced
Since fecc4dd, placeholder keys can't be compared by reference. Add a placeholder kind and defined placeholder values.
Diffstat (limited to 'srcs')
-rw-r--r--srcs/juloo.keyboard2/KeyModifier.java22
-rw-r--r--srcs/juloo.keyboard2/KeyValue.java30
2 files changed, 30 insertions, 22 deletions
diff --git a/srcs/juloo.keyboard2/KeyModifier.java b/srcs/juloo.keyboard2/KeyModifier.java
index b9348f2..454cc29 100644
--- a/srcs/juloo.keyboard2/KeyModifier.java
+++ b/srcs/juloo.keyboard2/KeyModifier.java
@@ -122,17 +122,7 @@ class KeyModifier
case Char: name = apply_fn_char(k.getChar()); break;
case Keyevent: name = apply_fn_keyevent(k.getKeyevent()); break;
case Event: name = apply_fn_event(k.getEvent()); break;
- case String:
- switch (k.getString())
- {
- case "":
- if (k == KeyValue.getKeyByName("f11_placeholder"))
- name = "f11";
- else if (k == KeyValue.getKeyByName("f12_placeholder"))
- name = "f12";
- break;
- }
- break;
+ case Placeholder: name = apply_fn_placeholder(k.getPlaceholder()); break;
}
return (name == null) ? k : KeyValue.getKeyByName(name);
}
@@ -160,6 +150,16 @@ class KeyModifier
}
}
+ private static String apply_fn_placeholder(KeyValue.Placeholder p)
+ {
+ switch (p)
+ {
+ case F11: return "f11";
+ case F12: return "f12";
+ default: return null;
+ }
+ }
+
/** Return the name of modified key, or [null]. */
private static String apply_fn_char(char c)
{
diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java
index 21a3baf..4a6223e 100644
--- a/srcs/juloo.keyboard2/KeyValue.java
+++ b/srcs/juloo.keyboard2/KeyValue.java
@@ -68,9 +68,16 @@ final class KeyValue
AUTOFILL,
}
+ public static enum Placeholder
+ {
+ REMOVED,
+ F11,
+ F12
+ }
+
public static enum Kind
{
- Char, String, Keyevent, Event, Modifier, Editing
+ Char, String, Keyevent, Event, Modifier, Editing, Placeholder
}
// Behavior flags.
@@ -154,6 +161,11 @@ final class KeyValue
return Editing.values()[(_code & VALUE_BITS)];
}
+ public Placeholder getPlaceholder()
+ {
+ return Placeholder.values()[(_code & VALUE_BITS)];
+ }
+
/* Update the char and the symbol. */
public KeyValue withChar(char c)
{
@@ -257,14 +269,10 @@ final class KeyValue
FLAG_SPECIAL | FLAG_SECONDARY | FLAG_SMALLER_FONT);
}
- // Within VALUE_BITS
- private static int placeholder_unique_id = 0;
-
- /** Use a unique id as the value because the symbol is shared between every
- placeholders (it is the empty string). */
- private static KeyValue placeholderKey()
+ /** A key that do nothing but has a unique ID. */
+ private static KeyValue placeholderKey(Placeholder id)
{
- return new KeyValue("", Kind.String, placeholder_unique_id++, 0);
+ return new KeyValue("", Kind.Placeholder, id.ordinal(), 0);
}
private static KeyValue fallbackMakeKey(String name)
@@ -349,9 +357,9 @@ final class KeyValue
case "space": return charKey("\r", ' ', FLAG_KEY_FONT | FLAG_SECONDARY);
case "nbsp": return charKey("\u237d", '\u00a0', FLAG_SMALLER_FONT);
- case "removed": return placeholderKey();
- case "f11_placeholder": return placeholderKey();
- case "f12_placeholder": return placeholderKey();
+ case "removed": return placeholderKey(Placeholder.REMOVED);
+ case "f11_placeholder": return placeholderKey(Placeholder.F11);
+ case "f12_placeholder": return placeholderKey(Placeholder.F12);
case "copy": return editingKey("copy", Editing.COPY);
case "paste": return editingKey("paste", Editing.PASTE);