cut and copy with built in keys only if text is selected (#1019)
Some checks failed
Make Apk CI / Build-Apk (push) Has been cancelled
Check translations / check-translations (push) Has been cancelled
Check layouts / Generated files (push) Has been cancelled
Check layouts / check_layout.output (push) Has been cancelled

cut and copy with built in keys only if text is selected to keep existing clipboard content. does not work for key combinations like ctrl+x or ctrl+c.
This commit is contained in:
alotbsol555 2025-06-21 22:15:22 +02:00 committed by GitHub
parent c6da6d6ab5
commit 9d12981b34
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -234,9 +234,9 @@ public final class KeyEventHandler
{ {
switch (ev) switch (ev)
{ {
case COPY: send_context_menu_action(android.R.id.copy); break; case COPY: if(is_selection_not_empty()) send_context_menu_action(android.R.id.copy); break;
case PASTE: send_context_menu_action(android.R.id.paste); break; case PASTE: send_context_menu_action(android.R.id.paste); break;
case CUT: send_context_menu_action(android.R.id.cut); break; case CUT: if(is_selection_not_empty()) send_context_menu_action(android.R.id.cut); break;
case SELECT_ALL: send_context_menu_action(android.R.id.selectAll); break; case SELECT_ALL: send_context_menu_action(android.R.id.selectAll); break;
case SHARE: send_context_menu_action(android.R.id.shareText); break; case SHARE: send_context_menu_action(android.R.id.shareText); break;
case PASTE_PLAIN: send_context_menu_action(android.R.id.pasteAsPlainText); break; case PASTE_PLAIN: send_context_menu_action(android.R.id.pasteAsPlainText); break;
@ -466,6 +466,13 @@ public final class KeyEventHandler
_recv.selection_state_changed(false); _recv.selection_state_changed(false);
} }
boolean is_selection_not_empty()
{
InputConnection conn = _recv.getCurrentInputConnection();
if (conn == null) return false;
return (conn.getSelectedText(0) != null);
}
public static interface IReceiver public static interface IReceiver
{ {
public void handle_event_key(KeyValue.Event ev); public void handle_event_key(KeyValue.Event ev);