forked from extern/Unexpected-Keyboard
Fix placeholder key not replaced
Since fecc4dd
, placeholder keys can't be compared by reference.
Add a placeholder kind and defined placeholder values.
This commit is contained in:
parent
5f283cd0cd
commit
2539feadcd
@ -122,17 +122,7 @@ class KeyModifier
|
|||||||
case Char: name = apply_fn_char(k.getChar()); break;
|
case Char: name = apply_fn_char(k.getChar()); break;
|
||||||
case Keyevent: name = apply_fn_keyevent(k.getKeyevent()); break;
|
case Keyevent: name = apply_fn_keyevent(k.getKeyevent()); break;
|
||||||
case Event: name = apply_fn_event(k.getEvent()); break;
|
case Event: name = apply_fn_event(k.getEvent()); break;
|
||||||
case String:
|
case Placeholder: name = apply_fn_placeholder(k.getPlaceholder()); break;
|
||||||
switch (k.getString())
|
|
||||||
{
|
|
||||||
case "":
|
|
||||||
if (k == KeyValue.getKeyByName("f11_placeholder"))
|
|
||||||
name = "f11";
|
|
||||||
else if (k == KeyValue.getKeyByName("f12_placeholder"))
|
|
||||||
name = "f12";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
return (name == null) ? k : KeyValue.getKeyByName(name);
|
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]. */
|
/** Return the name of modified key, or [null]. */
|
||||||
private static String apply_fn_char(char c)
|
private static String apply_fn_char(char c)
|
||||||
{
|
{
|
||||||
|
@ -68,9 +68,16 @@ final class KeyValue
|
|||||||
AUTOFILL,
|
AUTOFILL,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static enum Placeholder
|
||||||
|
{
|
||||||
|
REMOVED,
|
||||||
|
F11,
|
||||||
|
F12
|
||||||
|
}
|
||||||
|
|
||||||
public static enum Kind
|
public static enum Kind
|
||||||
{
|
{
|
||||||
Char, String, Keyevent, Event, Modifier, Editing
|
Char, String, Keyevent, Event, Modifier, Editing, Placeholder
|
||||||
}
|
}
|
||||||
|
|
||||||
// Behavior flags.
|
// Behavior flags.
|
||||||
@ -154,6 +161,11 @@ final class KeyValue
|
|||||||
return Editing.values()[(_code & VALUE_BITS)];
|
return Editing.values()[(_code & VALUE_BITS)];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Placeholder getPlaceholder()
|
||||||
|
{
|
||||||
|
return Placeholder.values()[(_code & VALUE_BITS)];
|
||||||
|
}
|
||||||
|
|
||||||
/* Update the char and the symbol. */
|
/* Update the char and the symbol. */
|
||||||
public KeyValue withChar(char c)
|
public KeyValue withChar(char c)
|
||||||
{
|
{
|
||||||
@ -257,14 +269,10 @@ final class KeyValue
|
|||||||
FLAG_SPECIAL | FLAG_SECONDARY | FLAG_SMALLER_FONT);
|
FLAG_SPECIAL | FLAG_SECONDARY | FLAG_SMALLER_FONT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Within VALUE_BITS
|
/** A key that do nothing but has a unique ID. */
|
||||||
private static int placeholder_unique_id = 0;
|
private static KeyValue placeholderKey(Placeholder id)
|
||||||
|
|
||||||
/** Use a unique id as the value because the symbol is shared between every
|
|
||||||
placeholders (it is the empty string). */
|
|
||||||
private static KeyValue placeholderKey()
|
|
||||||
{
|
{
|
||||||
return new KeyValue("", Kind.String, placeholder_unique_id++, 0);
|
return new KeyValue("", Kind.Placeholder, id.ordinal(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static KeyValue fallbackMakeKey(String name)
|
private static KeyValue fallbackMakeKey(String name)
|
||||||
@ -349,9 +357,9 @@ final class KeyValue
|
|||||||
case "space": return charKey("\r", ' ', FLAG_KEY_FONT | FLAG_SECONDARY);
|
case "space": return charKey("\r", ' ', FLAG_KEY_FONT | FLAG_SECONDARY);
|
||||||
case "nbsp": return charKey("\u237d", '\u00a0', FLAG_SMALLER_FONT);
|
case "nbsp": return charKey("\u237d", '\u00a0', FLAG_SMALLER_FONT);
|
||||||
|
|
||||||
case "removed": return placeholderKey();
|
case "removed": return placeholderKey(Placeholder.REMOVED);
|
||||||
case "f11_placeholder": return placeholderKey();
|
case "f11_placeholder": return placeholderKey(Placeholder.F11);
|
||||||
case "f12_placeholder": return placeholderKey();
|
case "f12_placeholder": return placeholderKey(Placeholder.F12);
|
||||||
|
|
||||||
case "copy": return editingKey("copy", Editing.COPY);
|
case "copy": return editingKey("copy", Editing.COPY);
|
||||||
case "paste": return editingKey("paste", Editing.PASTE);
|
case "paste": return editingKey("paste", Editing.PASTE);
|
||||||
|
Loading…
Reference in New Issue
Block a user