diff --git a/srcs/juloo.keyboard2/KeyValue.java b/srcs/juloo.keyboard2/KeyValue.java index 7c5dada..2c5a03b 100644 --- a/srcs/juloo.keyboard2/KeyValue.java +++ b/srcs/juloo.keyboard2/KeyValue.java @@ -233,7 +233,8 @@ public final class KeyValue implements Comparable /* Update the char and the symbol. */ public KeyValue withChar(char c) { - return new KeyValue(String.valueOf(c), Kind.Char, c, getFlags()); + return new KeyValue(String.valueOf(c), Kind.Char, c, + getFlags() & ~(FLAG_KEY_FONT | FLAG_SMALLER_FONT)); } public KeyValue withKeyevent(int code) @@ -248,6 +249,7 @@ public final class KeyValue implements Comparable public KeyValue withSymbol(String symbol) { + int flags = getFlags() & ~(FLAG_KEY_FONT | FLAG_SMALLER_FONT); switch (getKind()) { case Char: @@ -259,11 +261,13 @@ public final class KeyValue implements Comparable case Modifier: case Editing: case Placeholder: - return new KeyValue(symbol, _code, _code, getFlags()); + if (symbol.length() > 1) + flags |= FLAG_SMALLER_FONT; + return new KeyValue(symbol, _code, _code, flags); case Macro: - return makeMacro(symbol, getMacro(), 0); + return makeMacro(symbol, getMacro(), flags); default: - return makeMacro(symbol, new KeyValue[]{ this }, 0); + return makeMacro(symbol, new KeyValue[]{ this }, flags); } } @@ -477,6 +481,8 @@ public final class KeyValue implements Comparable public static KeyValue makeMacro(String symbol, KeyValue[] keys, int flags) { + if (symbol.length() > 1) + flags |= FLAG_SMALLER_FONT; return new KeyValue(new Macro(keys, symbol), Kind.Macro, 0, flags); } diff --git a/test/juloo.keyboard2/KeyValueParserTest.java b/test/juloo.keyboard2/KeyValueParserTest.java index b7abbef..d56b6b5 100644 --- a/test/juloo.keyboard2/KeyValueParserTest.java +++ b/test/juloo.keyboard2/KeyValueParserTest.java @@ -93,7 +93,7 @@ public class KeyValueParserTest public void parse_key_event() throws Exception { Utils.parse("a:keyevent:85", KeyValue.keyeventKey("a", 85, 0)); - Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, 0)); + Utils.parse("symbol:keyevent:85", KeyValue.keyeventKey("symbol", 85, KeyValue.FLAG_SMALLER_FONT)); Utils.parse("macro:keyevent:85,abc", KeyValue.makeMacro("macro", new KeyValue[]{ KeyValue.keyeventKey("", 85, 0), KeyValue.makeStringKey("abc") @@ -112,7 +112,7 @@ public class KeyValueParserTest Utils.parse(":str:'Foo'", KeyValue.makeStringKey("Foo")); Utils.parse(":str flags='dim':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY)); Utils.parse(":str symbol='Symbol':'Foo'", KeyValue.makeStringKey("Foo").withSymbol("Symbol")); - Utils.parse(":str symbol='Symbol' flags='dim':'f'", KeyValue.makeStringKey("f").withSymbol("Symbol").withFlags(KeyValue.FLAG_SECONDARY)); + Utils.parse(":str symbol='Symbol' flags='dim':'f'", KeyValue.makeStringKey("f").withSymbol("Symbol").withFlags(KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT)); Utils.parse(":str flags='dim,small':'Foo'", KeyValue.makeStringKey("Foo", KeyValue.FLAG_SECONDARY | KeyValue.FLAG_SMALLER_FONT)); Utils.parse(":str flags=',,':'Foo'", KeyValue.makeStringKey("Foo")); // Unintentional Utils.expect_error(":unknown:Foo"); // Unknown kind diff --git a/test/juloo.keyboard2/KeyValueTest.java b/test/juloo.keyboard2/KeyValueTest.java index 8b1bfeb..6226d39 100644 --- a/test/juloo.keyboard2/KeyValueTest.java +++ b/test/juloo.keyboard2/KeyValueTest.java @@ -1,5 +1,6 @@ package juloo.keyboard2; +import android.view.KeyEvent; import juloo.keyboard2.KeyValue; import org.junit.Test; import static org.junit.Assert.*; @@ -13,6 +14,12 @@ public class KeyValueTest { assertEquals(KeyValue.makeStringKey("Foo").withSymbol("Symbol"), KeyValue.makeMacro("Symbol", new KeyValue[] { KeyValue.makeStringKey("Foo") }, 0)); + assertEquals(KeyValue.getSpecialKeyByName("tab"), + KeyValue.keyeventKey(0xE00F, KeyEvent.KEYCODE_TAB, KeyValue.FLAG_KEY_FONT | KeyValue.FLAG_SMALLER_FONT)); + assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("t"), + KeyValue.keyeventKey("t", KeyEvent.KEYCODE_TAB, 0)); + assertEquals(KeyValue.getSpecialKeyByName("tab").withSymbol("tab"), + KeyValue.keyeventKey("tab", KeyEvent.KEYCODE_TAB, KeyValue.FLAG_SMALLER_FONT)); } @Test