From 366ee5ae28e33db0c9fca2597a78d748140b312f Mon Sep 17 00:00:00 2001 From: Helium314 Date: Sun, 4 May 2025 20:33:41 +0200 Subject: [PATCH] workaround for page start / page end toolbar keys not working in compose text fields fixes GH-1477 --- .../keyboard/latin/inputlogic/InputLogic.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java index 8e3282cc4..76fdf66c6 100644 --- a/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java +++ b/app/src/main/java/helium314/keyboard/latin/inputlogic/InputLogic.java @@ -773,10 +773,27 @@ public final class InputLogic { KeyEvent.KEYCODE_DPAD_LEFT : KeyEvent.KEYCODE_DPAD_RIGHT, KeyEvent.META_CTRL_ON); break; case KeyCode.MOVE_START_OF_PAGE: + final int selectionEnd = mConnection.getExpectedSelectionEnd(); sendDownUpKeyEventWithMetaState(KeyEvent.KEYCODE_MOVE_HOME, KeyEvent.META_CTRL_ON); + if (mConnection.getExpectedSelectionStart() > 0 && mConnection.getExpectedSelectionEnd() == selectionEnd) { + // unchanged, and we're not at the top -> try a different method (necessary for compose fields) + mConnection.setSelection(0, 0); + } break; case KeyCode.MOVE_END_OF_PAGE: + final int selectionStart = mConnection.getExpectedSelectionEnd(); sendDownUpKeyEventWithMetaState(KeyEvent.KEYCODE_MOVE_END, KeyEvent.META_CTRL_ON); + if (mConnection.getExpectedSelectionStart() == selectionStart) { + // unchanged, try fallback e.g. for compose fields that don't care about ctrl + end + // we just move to a very large index, and hope the field is prepared to deal with this + // getting the actual length of the text for setting the correct position can be tricky for some apps... + try { + mConnection.setSelection(Integer.MAX_VALUE, Integer.MAX_VALUE); + } catch (Exception e) { + // better catch potential errors and just do nothing in this case + Log.i(TAG, "error when trying to move cursor to last position: " + e); + } + } break; case KeyCode.UNDO: sendDownUpKeyEventWithMetaState(KeyEvent.KEYCODE_Z, KeyEvent.META_CTRL_ON);