Add editing keys: copy, paste, cut, select all

This commit is contained in:
Jules Aguillon 2022-11-13 16:45:57 +01:00
parent 078dbcd5ff
commit 2aa98de7aa
4 changed files with 52 additions and 1 deletions

View File

@ -28,6 +28,10 @@
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="19"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="20"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="21"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="22"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="23"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="24"/>
<juloo.keyboard2.ExtraKeyCheckBoxPreference app:index="25"/>
</PreferenceScreen>
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_category_typing">

View File

@ -36,6 +36,10 @@ public class ExtraKeyCheckBoxPreference extends CheckBoxPreference
"£",
"switch_greekmath",
"capslock",
"copy",
"paste",
"cut",
"select_all",
};
public static boolean default_checked(String name)

View File

@ -65,6 +65,15 @@ class KeyEventHandler implements Config.IKeyEventHandler
break;
case Modifier:
break;
case Editing:
switch (key.getEditing())
{
case COPY: send_context_menu_action(android.R.id.copy); break;
case PASTE: send_context_menu_action(android.R.id.paste); break;
case CUT: send_context_menu_action(android.R.id.cut); break;
case SELECT_ALL: send_context_menu_action(android.R.id.selectAll); break;
}
break;
}
}
@ -137,6 +146,15 @@ class KeyEventHandler implements Config.IKeyEventHandler
_autocap.typed(text);
}
/** See {!InputConnection.performContextMenuAction}. */
void send_context_menu_action(int id)
{
InputConnection conn = _recv.getCurrentInputConnection();
if (conn == null)
return;
conn.performContextMenuAction(id);
}
public static interface IReceiver
{
public void switchToNextInputMethod();

View File

@ -52,9 +52,17 @@ final class KeyValue
FN, // Must be placed last to be applied first
}
public static enum Editing
{
COPY,
PASTE,
CUT,
SELECT_ALL,
}
public static enum Kind
{
Char, String, Keyevent, Event, Modifier
Char, String, Keyevent, Event, Modifier, Editing
}
// Behavior flags.
@ -132,6 +140,12 @@ final class KeyValue
return Modifier.values()[(_code & VALUE_BITS)];
}
/** Defined only when [getKind() == Kind.Editing]. */
public Editing getEditing()
{
return Editing.values()[(_code & VALUE_BITS)];
}
/* Update the char and the symbol. */
public KeyValue withChar(char c)
{
@ -247,6 +261,12 @@ final class KeyValue
addKeyeventKey(name, String.valueOf((char)symbol), code, flags | FLAG_KEY_FONT);
}
private static void addEditingKey(String name, String symbol, Editing action)
{
addKey(name, symbol, Kind.Editing, action.ordinal(),
FLAG_SPECIAL | FLAG_SECONDARY | FLAG_SMALLER_FONT);
}
// Within VALUE_BITS
private static int placeholder_unique_id = 0;
@ -332,6 +352,11 @@ final class KeyValue
addPlaceholderKey("removed");
addPlaceholderKey("f11_placeholder");
addPlaceholderKey("f12_placeholder");
addEditingKey("copy", "copy", Editing.COPY);
addEditingKey("paste", "paste", Editing.PASTE);
addEditingKey("cut", "cut", Editing.CUT);
addEditingKey("select_all", "s. all", Editing.SELECT_ALL);
}
static final HashMap<String, String> keys_descr = new HashMap<String, String>();